문제

Is it possible to filter over a DateTimeField to get all objects who have a DateTimeField later to the given date ? For instance :

class MyObject(models.Model):
    updated_date = models.DateTimeField()

in a view :

given_date = someDateTime
new_items = MyObject.objects.filter(updated_date__after = given_date)
도움이 되었습니까?

해결책

Use __gt in a double underscore notation:

new_items = MyObject.objects.filter(updated_date__gt=given_date)

Relevant threads:

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top