Search code examples
djangodjango-admindjango-rest-frameworkdjango-rest-auth

Django count today's logged in users


I want to show on my admin interface the count of the users those did log in today. My admin interface looks like following:

enter image description here

When I print from my view

 count = User.objects.filter(last_login=timezone.now()).count()

it gives me 0 as both the date/time format are different. i.e. 2016-06-01 14:58:29.079000+00:00

How can I get that count on my admin interface somewhere?


Solution

  • You have to get the date from the timezone.now() and then use filter 'startswith' to filter by date:

    count = User.objects.filter(last_login__startswith=timezone.now().date()).count()
    

    In addition to add this column to your Django Admin Interface you can check this Custom columns using Django admin