41👍
✅
This will give you a list of unique posting dates:
Posts.objects.filter(draft=False).dates('post_date','month',order='DESC')
Of course you might not need the draft filter, and change ‘post_date’ to your field name, etc.
14👍
I found the answer to my own question.
It’s on this page in the documentation.
There’s a function called dates that will give you distinct dates. So I can do
Entry.objects.dates(‘pub_date’,’month’) to get a list of datetime objects, one for each year/month.
- How do I restrict access to admin pages in Django?
- Django: Highlight current page in navbar
- ALLOWED_HOSTS and Django
- Build_absolute_uri with HTTPS behind reverse proxy
1👍
You should be able to get all the info you describe from the built-in views. Can you be more specific as to what you cannot get? This should have everything you need:
django.views.generic.date_based.archive_month
Reference page (search for the above string on that page)
Source:stackexchange.com