I need to retrieve IDs from multiple queries and add them into a list. Then I tried This raised error as list cannot be added to queryset. so, I tried, This works but, all_products has a mix of int and tuple values [10, 20, 30, (2,), (2,), (1,)] I need them to be [10, 20, 30, 2, 2, 1] Answer
Tag: django
Django execute previous action on refresh
I have tried to add a book in to the database using an HTML form. After the submission, the page redirect to a page where all the books are listed .Then whenever I refresh the page , the data is became duplicated. How do I resolve this problem? urls.py views.py Template file: Answer This is most common problem, the thing
AttributeError: ‘tuple’ object has no attribute ‘model’. How to fix this error?
I’m new to Django. Please help me to solve this error. I’m not getting any solution. I tried many stackoverflow solutions and GitHub solutions but I’m not getting where the error is coming from. urls.py models.py views.py serializers.py Exception log Here is the github link of the app – Django I tried many stackoverflow solutions but I am not understanding
Can’t create superuser in Django using custom user
I got this error when i try to run manage.py createsuperuser TypeError: UserManager.create_superuser() missing 1 required positional argument: ‘username’ My User model: and in my settings.py file: How can i solve this? Im new in Django, documentation is confused to me… I already tried remove AUTH_USER_MODEL = ‘usuarios.User’ or remove username attribute from class User Answer To create superuser with
Django View, foreign key field is killing performance
MyObjects definition: View definition: I do some calculations in my view that are irrelevant and my view takes around 3 seconds for 5000 objects if my_dict[str(my_obj.foreign_key_field)] += 1 is commented out. However, when that line uncommented, my view takes 20seconds. It must be because this field is a foreign key field as none of my other fields are foreign keys.
How to add a new “comment” or “flag” field to every model field of existing model?
Disclaimer: I can wipe out the database anytime. So while answering this, please don’t care about migrations and stuff. Imagine me having a model with multiple values: Now I want to add a comment to be stored for every value of that model. For example I want to add a comment “measured in winter” to the temperature model field. What
Reducing number of repeated queries in Django when creating new objects in a loop
I’m populating a database using Django from an Excel sheet. In the example below, the purchases list simulates the format of that sheet. My problem is that I’m repeatedly using Customer.objects.get to retrieve the same Customer object when creating new Purchase entries. This results in repeated database queries for the same information. I’ve tried using customers = Customer.objects.all() to read
Trying to add a field to Django many-to-many relation
Right now I’m working on a Django project responsible for the warehouse management system. I got products, customers, warehouse branches, product types, orders, etc… products can be [Milk 1L bottle, cheese 500g pack, ….] The problem I have been facing is that I’m trying to make a many-to-many relationship between orders and products so I can track the products sold
I would like to limit the borrowing objects in my Django app
I have an app that displays games and users can borrow them. I want to limit the amount of borrowed games for each user to max 3 games. I created two models borrow and games. The methods work well except for the max borrowing. Answer You can check whether he has borrowed more than 3 games in form.is_valid() if like
how to select more options in “ManyToManyField()”?
i wanted to create a tag option for a a music model , well mainly musics accept more than one tag and there are amny kind of genres and tags ,so i wanted to make a ManyToManyField() that you can set more than 1 value ,also if you tag is not in add it in. to do that i thought