Compare Year And Month Of Date Field To Be Greater Than
I'm going to do this query: today = datetime.date.today() year=today.year month=today.month news=News.objects.filter(date__year__lt = year,date__month__lt=month) Note:News object
Solution 1:
You can't append __lt
onto to __year
or __month
. Only the last double-underscored bit is consider the qualifier, everything before it is treated as a traversal, i.e. Django will try to look up a field named year
on join table named date
, which is obviously not correct.
For something like this you'll need to just compare the date directly:
date = datetime.date(year, month, 1)
news = News.objects.filter(date__lt=date)
Post a Comment for "Compare Year And Month Of Date Field To Be Greater Than"