0👍
Unfortunatelly, you can’t do that with F expressions: https://code.djangoproject.com/ticket/16487
You can either write a custom sql query using the .raw() method, or you can use standard filters to get this to work, but only if all your models have the same days_due value, which is probably not the case – but just in case, you can do it like this:
Item.objects.filter(issue_date__lte=now - datetime.timedelta(days=days))
👤samu
0👍
I think you can’t do this in a db agnostic way. I would use an extra(select)
to add a is_due
field to your query. Something like (not tested):
Item.objects.extra(select={'is_due': 'issue_date + days_due'})
could work on a postgres database. Put the extra select
in a custom manager to isolate the database specific code.
- [Django]-Is it possible to use query parameters on the Django Admin Site
- [Django]-Django – WSGI script cannot be loaded as Python module
- [Django]-How to properly show image stored from a remote file server to a django HTML template?
Source:stackexchange.com