Reputation: 1
I am trying to write a report where usernames must be listed grouped by date(date_joined)?
For example:
2015-12-03 - User1 - User2
2015-12-04 - User3 - User4
How do I approach this problem?
I tried https://coderwall.com/p/z126aa/django-count-user-growth-each-month but it gives only the count but what I need is usernames by date.
Upvotes: 0
Views: 52
Reputation: 599906
Presumably you want to output this report in the template. In which case the easiest thing is just to get all Users sorted by date, then use the regroup
tag in the template to do the grouping.
View:
users = User.objects.all().order_by('date_joined')
Template:
{% regroup users by date_joined as user_date_list %}
<ul>
{% for date in user_date_list %}
<li>{{ date.grouper }}
<ul>
{% for item in date.list %}
<li>{{ item.username }}</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
Upvotes: 2