I defined Article
model at models.py. And I defined created
by models.DateTimeField
in Article
class.
I want to get articles by specified year value but I can not catch it by one of my case. But case of other approach is fine. Why ?
models.py
class Article(models.Model):
created = models.DateTimeField(auto_now_add=True)
python manage.py shell
>>> Article.objects.filter(created__year=2014).all()
<QuerySet []>
>>> for el in Article.objects.all():
... if el.created.year == 2014:
... print('2014')
...
2014
>>>