I have model Car, Listing and Website. I want to filter all car objects that have listing object on the given website but the listing needs to be active. To get all car objects that have listing object on the given website: But how do I filter out inactive listings? I want something like: Answer You would do an extra
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 complex partitioning & ordering for tree Table
I’m using Django with PostgreSQL as my Backend-Stack for an application of which the main feature is a complex, multilevel table displaying annotated time-series-data for different products. So …
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, have model to be related to many instances of itself
I have a model: I want it to have a sub_industries field that will hold all of its sub industries, which should be instances of Industry model. I cannot be ManyToMany because each industry has only one parent industry. Answer You can add a ForeignKey to itself with: You can use NULL/None to express that an industry has no parent.
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
How to work around Django’s lack of composite keys in this complicated case?
I can’t seem to figure out how to work around the lack of composite keys in Django for the following case. I’m going to write the schema I’d like using SQLite3 dialect. (The only thing below that might be unfamiliar to someone who knows SQL but not sqlite is sqlite’s “WITHOUT ROWID” clause. By default, sqlite adds a hidden integer