Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 Django 中是否有一种简单的方法来查找用户数、具有配置文件对象的用户数以及理想的每月登录数(但可以使用 Google Analytics 来做到这一点)。我可以在管理界面中看到所有数据,但我不确定如何在 Python 领域获得这些数据。有没有人见过任何计算用户对象数量的例子?
统计用户数:
import django.contrib.auth django.contrib.auth.models.User.objects.all().count()
您可以使用它来计算配置文件对象的数量(假设每个用户最多有 1 个配置文件),例如,如果 Profile 是配置文件模型:
Profile.objects.all().count()
要计算一个月内的登录次数,您需要创建一个表,记录每个登录并带有时间戳。然后是再次使用 count() 的问题。