def ctx_dic_history(request):
ctx_history = {} ctx_history['dates'] = Post.objects.dates('created','month').distinct() return ctx_history
If I put {{ dates }} in the aside, it returns the following:
<QuerySet [datetime.date(2022, 7, 1), datetime.date(2022, 8, 1), datetime.date(2022, 9, 1), datetime.date(2022, 10, 1)]>
Now I want to go through that queryset, but I can't get what I need: I want them to be sorted descending first, that is, the most recent month on top. Second, I want to access the month and the year, that is, something like "August 2022" appears.
{% for item in dates %} <a href="">Probando</a> {% endfor %}
With that I can iterate over the items that this queryset brings me, but I don't know how to access the date in question for each item in the queryset. If you can give me a hand I would appreciate it in advance. If I manage to get it to work, I'll definitely post the answer that worked for me. Thank you so much
-- You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/96f58712-88e9-4eae-94f6-909918f2045en%40googlegroups.com.
No comments:
Post a Comment