Skip to content
Advertisement

Tag: django-models

get more than two foreign keys from another django table and perform calculations on them

In the Django app, I have created two tables. Product Invoice I have one table called Product which contains product name and product price columns are given. Then, I have a second table named Invoice which contains a product name(foreign key), product price(foreign key), discount, and total. My concern is how can I import both the values from the Product

Django merge QuerySet while keeping the order

i’m trying to join together 2 QuerySets. Right now, I’m using the | operator, but doing it this way won’t function as an “append”. My current code is: I need the elements from querysetA to be before querysetB. Is it even possible to accomplish while keeping them just queries? Answer This can be solved by using annotate to add a

Django – Retrieve all manytomany field objects related to a specific model

I have my models reviews and news, both having a manytomany relation with Category model. Now I want to get all the categories associated with only one of these two models. For example, to get all categories associated with News model, I tried querying database with News.categories.all() but got AttributeError: ‘ManyToManyDescriptor’ object has no attribute ‘objects’. News Model: Reviews Model:

Inherit choice class to extend it?

I have a field in my models.py that accepts choices determined in a class: The choice class is this: My doubt is how can I inherit this UserChoices class to another choice class, in order to extend it with another options. I tried the following: But it gives me a migration error: Obviously this example is simplified, the actual code

Advertisement