Sum of F() expression and timedelta created from F() expression

后端 未结 2 662
栀梦
栀梦 2021-01-14 00:47

My Proposal model is defined as follows:

class Proposal(models.Model):
    scheduled_time = models.DateTimeField()
    duration = models.IntegerField() # sto         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-14 00:58

    F()-expressions works only with django (as they return instances of specific objects). You can't pass them to timedelta or whatever except some of the django queryset methods.

    So you'd better add new field to you model:

    class Proposal(models.Model):
        scheduled_time = models.DateTimeField()
        duration = IntegerField()
        end = models.DateTimeField(default=self.scheduled_time + timedelta(minutes=self.duration))
    

提交回复
热议问题