I made it that way: prev_months = Article.objects.dates('add_date', > 'month').filter(add_date__lt=datetime.date(int(year), int(month), 1))[:5] > next_months = Article.objects.dates('add_date', > 'month').filter(add_date__gte=datetime.date(int(year), int(month) + 1, > 1))[:5]
On Wednesday, June 27, 2012 9:28:27 PM UTC+2, galgal wrote: > > I have a model Article. It has a datetime field, title and description. > How can I get last 5 months from now, where there is at least 1 article > added? Other words - how to get last 5 months which are not empty? > -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/Qa_SJtAS6KwJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.