I am trying to rewrite a function view that download files into a classview. However I don’t see how to do it properly with the right methods, since I have an argument from the url. Then I do not which on of the class view I should be using. I did an attemps that is worrking, but I do not
Tag: django
Unsupported lookup ‘category’ for CharField or join on the field not permitted
models.py: This is my views.py file. I show error at: bestseller = Product.objects.filter(product__category__icontains=’BestSeller’) views.py: I want to Bestseller category product at index.html I use Django 4 and pyhton 3.9 Answer You can’t use CharField as a ForeignKey. It should be like t…
Nested Serializer save post foreign key in django
In my project, the relationship between Product and Group is ManytoOne. When I tried to post a new product, it cannot work. I’m sure there are more issues with this code and I will appreciate a detailed answer, because I am new to Django and Python. Thank you in advance. models.py serializers.py views.p…
DRF – Relate an object to another using views, serializers and foreign key
Basically I have two models with one-to-one relationship. And I want retrieve information from one, when I call the other. My models: So I can just call an POST and create an Customer, that customer will have id, first_name and last_name. For now everything is working. But when I try to call my endpoint to cr…
How to run a forloop in django views.py?
I want to iterate over a queryset and if there is a new user added, I want to add some points for a specific user. To be more clear with what i am building: => I am writing a referral system logic in django. The referral system works fine now, but what i want to implement is this. When i
Override (save_model) in django admin for All models/apps in projects
How could I implement override save method for all models in all Apps inside Admin panel? I can implement it in one or two models “inherit and adding it in register method”, but I really need it to execute whenever admin clicks save in Admin panel and implement some code before save. Answer In my …
VSCode not using test database for Django tests
I’ve got an issue where VSCode’s test feature uses the production database instead of creating a test database. tests.py I have previously created 1 instance of SomeModel, so if you do SomeModel.objects.all() in the shell, it returns a queryset with that one instance. If I run this test from vscod…
Edit Form Submit handler for a Model
I have a fairly simple django model in a Wagtail CMS; essentially: I need to perform an action when this model is saved via the Wagtail model edit form (eg /admin/section/thingy/123/edit). Currently, I have registered a post_save signal, however this has resulted in the method being called when the model is s…
Django join tables with ForeignKey
I’m trying to join 3 tables with ForeignKey but it returns Null values. I’m using select related and also I tried Insight.objects.all() but both are not working. Here are my models: My View: Answer I solved my problem by the below, I could update the DB with the result of the below query
serializer not being called AttributeError: ‘str’ object has no attribute ‘_meta’
I modified the Auth User by using AbstractUser Class. Registered it in settings. Everything else is working I can create an instance using the User Model BUT The Problem comes during the serialization. My serializer doesn’t throw any error, but any time I try and use the serializer.data I get AttributeE…