开发者

Best way to get future event from a date and a time attribute

In one of my Django application I have an object with both a date and a time attribute, and i don't wish to use a datetime single attribute.

For th开发者_如何转开发e sake of example let's call this object "Meeting":

class Meeting(models.Model):
    publication_date = models.DateField()
    publication_time = models.TimeField()

Now I would like to get all the Meetings in the future given the current time

I am currently using this query:

Meeting.objects.filter(publication_date__gte=datetime.date.today()).exclude(publication_date= datetime.date.today(), publication_time__lt = datetime.datetime.now()).order_by('publication_date', 'publication_time')

But I feel like there might be a more efficient way


Nope that would be the correct way to do it given the constraint of not using a datetime field. Why you don't want to use a datetime field I don't know.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜