Skip to content
Advertisement

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 have a

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 specific equipment_id and is the latest

django: group by extracting month and year from a date

im trying to get a list of invoicepositions where there hasn’t been payed an payout to a person. Looking in the internet i came to this “Solution” but the query, that comes out is: so he added “created_at” and the id from the invoiceposition model although i don’t want that! for example i have the following 4 lines in the

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 (Model): There are users, they can invite each

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 objects, but becomes horribly inefficient

MySQL GROUP BY slows down query x1000 times

I’m struggling with setting up proper, effective index for my Django application which uses MySQL database. The problem is about article table which for now has a little more than 1 million rows and querying isn’t as fast as we want. Article table structure looks more or less like below: After many tries I came that below index gives best

Advertisement