私の提案モデルは次のように定義されています。
class Proposal(models.Model):
scheduled_time = models.DateTimeField()
duration = models.IntegerField() # stores minutes as an integer
# (extra fields clipped for brevity's sake)
各プロポーザルオブジェクトに注釈を付けて、scheduled_time+期間のtimedelta表現で計算された「end」日時を指定しtimedelta(minutes=duration)
ます。ただし、F()式はの引数としては有効ではないようですtimedelta()
。
>>> from datetime import timedelta
>>> from django.db.models import F
>>> from schedule.models import Proposal
>>>
>>> proposals = Proposal.objects.all()
>>> annotated = proposals.annotate(
... end=F('scheduled_time')+timedelta(minutes=F('duration')))
Traceback (most recent call last):
File "<console>", line 1, in <module>
TypeError: unsupported type for timedelta minutes component: F
>>>
annotate()
F()式を使用してこの種のことは可能ですか?
編集:注釈の目的は、計算された終了時間をフィルタリング/除外できるようにすることです。