Update:
This answer is not useful. As entered
is a DateTimeField
the query will end up with a count of 1 for each value of entered
. This is not what the OP wanted. (Thanks dannyroa)
Changing the type of entered
to DateField
should help.
Original Answer
You can use Django's aggregation feature to do this. Something like this:
from django.db.models import Count
q = User.objects.annotate(Count('entered')).order_by('-entered')
for user in q[0:30]:
print "%s %s" % (user.entered, user.entered__count)
Update
You can slice the queryset and then pass it into the template.
# View
def my_view(*args, **kwargs):
queryset = User.objects.annotate(Count('entered')).order_by('-entered')
context = dict(queryset = queryset[0:30])
return render_to_response('my_template.html', context_instance = RequestContext(request, context))
# Template
{% for user in queryset %}
<td>{{ user.entered }}</td>
<td>{{ user.entered_count }}</td>
{% endfor %}