Q:

How to find number of users, number of users with a profile object, and monthly logins in Django

Is there an easy way in Django to find the number of Users, Number of Users with profile objects, and ideally number of logins per month (but could do this with Google Analytics). I can see all the data is there in the admin interface, but I'm unsure of how to get to it in Python land.  Has anyone seen any examples of counting number of user objects?

A:

Count the number of users:
import django.contrib.auth
django.contrib.auth.models.User.objects.all().count()

You can use the same to count the number of profile objects (assuming every user has at most 1 profile), e.g. if Profile is the profile model:
Profile.objects.all().count()

To count the number of logins in a month you'd need to create a table logging each login with a time stamp. Then it's a matter of using count() again.

