Skip to content

Tag: django

Django queryset to list of ids with integer values

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

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. 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 createsuperuser TypeError: UserManager.create_superuser() missing 1 required positional argument: ‘username’ My User model: and in my 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.

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