How can I use the F() object to do this with the Django ORM?

后端 未结 2 2104
旧巷少年郎
旧巷少年郎 2021-02-09 20:56

I encountered a model like this:

class Task(models.Model):
    timespan = models.IntegerField(null=True, blank=True)

class Todo(models.Model):
    limitdate = m         


        
2条回答
  •  无人及你
    2021-02-09 21:36

    The problem is that there's no TIMESPAN type on a database. So, F cannot return something that you can actually work with in this context. I'm not sure what type of field you actually used in your database, but the only way I can think of to do this is to the store the timespan as an integer consisting of seconds, add that to "today" as a timestamp, and then convert it back into a datetime which you can use to compare with limitdate. However, I'm unsure if Django will accept such complex logic with F.

提交回复
热议问题