Reputation: 67
I have a model like this:
class Article(models.Model):
title = models.CharField(max_length=200)
content = models.TextField()
create_time = models.DateTimeField(auto_now_add=True,null=True)
and I write a query statement in view function like this:
from datetime import time
start_time = time(hour=17)
end_time = time(hour=18)
articles = Article.objects.filter(create_time__time__between=(start_time,end_time))
but Django raise Exception django.core.exceptions.FieldError: Unsupported lookup 'between' for TimeField or join on the field not permitted.
,django document says it is right.if I want filter hour between 17 to 18,what should I do?
Upvotes: 3
Views: 1799
Reputation: 599630
No, the Django syntax for BETWEEN lookups is __range
, not __between
- that just appears to be a mistake in the __time
docs.
articles = Article.objects.filter(create_time__time__range=(start_time,end_time))
(I've submitted a PR to fix the docs.)
Upvotes: 5