Skip to content

Tag: django

Django QuerySet annotate with Subquery

given the following model I’m trying to get, my Pizza and the number of toppings, along with the top 3 other pizzas (top in terms of the number of toppings) The final result should be: a list containing the current pizza, and the top 3 pizzas, along with the count of toppings for all. So right now I hav…

django get record which is latest and other column value

I have a model with some columns, between them there are 2 columns: equipment_id (a CharField) and date_saved (a DateTimeField). I have multiple rows with the same equipment_id and but different date_saved (each time the user saves the record I save the now date time). I want to retrieve the record that has a…

Model hierarchy in Django [closed]

Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago. Improve this question Sorry for the long text Models are given: User Hierarchy class Hierarchy (…

Django get objects that are foreign key of two models

I have the following three models where Budget and Sale both contain a foreign key to Customer: I want to get a queryset of all Customer objects for which both a Budget and Sale exists. I initially tried getting the intersection of the customer field of all Budget and Sale objects: This returns the correct ob…