I read some model operation from Django’s document, and find this I’m curious that OR in WHERE is just basic concept, why Django think it’s a complex query?
Tag: django
Django ORM filter multiple fields using ‘IN’ statement
So I have the following model in Django: My goal is to have all the tuples grouped by the member with the most recent date. There are many ways to do it, one of them is using a subquery that groups by the member with max date_time and filtering member_loyalty with its results. The working sql for this solution is
Django: Really slow RunPython migration on related models
I am trying to optimise the speed of a migration on a large table (250K objects). The goal is to add to each row a user field based on the user of an object related to this row: I tried using an F expression but sadly django won’t allow relations in them. Note that I am mostly a beginner in
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
How can I take input from a text field in a Django page then update a SQL table with the response?
I am working on a site that will be used to clean up inactive Tableau workbooks. Logging into this site will allow my users to see their old workbooks and decide which ones to keep. This is going to …
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
Django annotate add interval to date
I am using postgres database with Django 2.2. I need to combine date and time field in model and add an interval of one day in it. I have done first part like this. Model.objects.annotate( end_dt=…
How to cotinuosly append data from DB2 server to sqlite using preferably django and if nothing else then python alone code
I am writing a django website that has some reports that pulls data based on DB2 database. Since I have only read only access to that database, I want the data from DB2 to be continuosly appended (or …
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
There is a way to check if a model field contains a substring?
I wanted to know if I can do things like this: More or less like this. In summary I want to search for a substring, not the string itself. Answer Take a look at Django contains and icontains