I want to do a query based on two fields of a model, a date, offset by an int, used as a timedelta
model.objects.filter(last_date__gte=datetime.now()-timedelta(days=F('interval')))
My model goes this way:
class Line(models.Model):
last_date = models.DateTimeField(auto_now=True)
interval = models.IntegerField(default=0)
I am using Django 2.0 and db.sqlite3
I found some sources What is the replacement for DateModifierNode in new versions of Django and Making queries using F() and timedelta at django but they were not helpful.
some suggested to use duration field, but I want the interval to be entered in days desperately, whenever I use duration field , the admin needs to enter that in [days hh:mm:ss] in admin forms.
And some gave a method
model.objects.filter(last_date__gte=datetime.now()-timedelta(days=1)*F('interval'))
which isn't working in db.sqlite3 and returning errors.
Please suggest me some solution,like admin using duration field and entering only days or some solution with integer field of days.