Skip to content
Advertisement

Tag: django

Django many-to-many: Best way to get elements in one related query set but exclude elements in other related query sets?

Consider these related models: In a view, I need to query to get all Bs related to a given A while excluding all Bs related with a set of other As. I need the grey area: My current, grossly inefficient approach is as follows: In my application, previous_As could have nearly 1,000 elements, which makes this approach extremely expensive. Is

Subquery django query to get biggest disctint values from objects and return those objects

So I have this query that I need to re-filter to get just the biggest taken_at field’s value from distinct meter id, but I cannot get the django orm’s/sql part to makes this query. <QuerySet [<Reading: [127] meter installation: 29, type: 1, taken: 2019-10-07 16:06:48.101453+00:00 value: 78.0000, comment: , VAT: 22.00>, <Reading: [126] meter installation: 41, type: 2, taken: 2019-10-07

How to use sql statement in django?

I want to get the latest date from my database. Here is my sql statement. It works in my database. But how can I use it in django? I tried these codes but it return error. These code are in views.py. Version 1: Error: Version 2: Error: I’ve defined reg_date at beginning of the class. What should I do for

Advertisement