python - Adding days to a date via the ORM -


how add days date in database? models are:

class item(models.model):     days_due = models.integerfield()     issue_date = models.datetimefield() 

i have function like:

def is_due(self):     time = self.days_due     days = timedelta(days=time)     due_date = self.issue_date + days     if timezone.now() >= due_date:         return true     else:         return false 

i able similar is_due function above database query, how done? i've referred documentation , not see way of combining f class timedeltas.

unfortunatelly, can't f expressions: https://code.djangoproject.com/ticket/16487

you can either write custom sql query using .raw() method, or can use standard filters work, if models have same days_due value, not case - in case, can this:

item.objects.filter(issue_date__lte=now - datetime.timedelta(days=days)) 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -