Django filter objects

人盡茶涼 提交于 2019-12-13 08:46:15

问题


I am fetching the users who did login today as follows:

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

I want to further filter results and fetch only those users whose username starts with yg_

How can I modify my code?


回答1:


Try this

count = User.objects.filter(last_login__year=timezone.now().year, 
      last_login__month=timezone.now().month,
      last_login__day=timezone.now().day,
      username__startswith='yg_').count()


来源:https://stackoverflow.com/questions/39244058/django-filter-objects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!