2

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?

Thinker
  • 5,326
  • 13
  • 61
  • 137

2 Answers2

2

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

Community
  • 1
  • 1
ezdookie
  • 1,477
  • 3
  • 15
  • 19
  • Yes the first answer solves my problem. Second answer is also correct, however what I want is bit different, not just adding a column but customizing widget. take a look here, if you would like to answer separately: http://stackoverflow.com/questions/37579348/django-show-object-count-on-admin-interface – Thinker Jun 02 '16 at 08:57
0

I think this should work:

count = User.objects.filter(last_login__startswith=timezone.now().date()).count()
Nimantha
  • 6,405
  • 6
  • 28
  • 69