it would probably be better to use a custom "Func"[1] and a custom "Query
Expression" [2] than user QuerySet.extra
[1] https://docs.djangoproject.com/en/1.9/ref/models/database-functions
[2] https://docs.djangoproject.com/en/1.9/ref/models/expressions/
On Mon, May 23, 2016 at 11:16 AM, Ketan
Take a look at the `extra` method of the queryset in Django. It allows you to
do what you are trying to do by raw SQL.
https://docs.djangoproject.com/en/1.9/ref/models/querysets/#django.db.models.query.QuerySet.extra
Check the above link, the example with `annotate` will be interesting for
Hi.
I am looking for a way to find a row which is closest to a specified
point in time, no matter if the row is before or after.
In plain SQL (using SQLite as example), it's very easy to do;
SELECT *,
abs(
strftime('%s','2015-05-21 23:05:00') - strftime('%s',`created`)
) AS timdif
3 matches
Mail list logo