【问题标题】:how to get object numbers in django models如何在 django 模型中获取对象编号
【发布时间】:2021-11-13 05:44:33
【问题描述】:

我是 Django 的新用户,我正在尝试打印模型中的对象总数,但下面的代码会打印带有标题的查询集。这是我的功能

def showthis(请求):

count= Item.objects.count()
print (count)

我需要获取模型项中的对象总数

【问题讨论】:

    标签: django count model


    【解决方案1】:
    items = Item.objects.all()
    print(items.count())
    

    【讨论】:

      猜你喜欢
      • 2020-04-06
      • 1970-01-01
      • 2011-03-24
      • 1970-01-01
      • 2015-08-03
      • 2011-07-07
      • 1970-01-01
      • 2021-02-14
      • 2019-01-25
      相关资源
      最近更新 更多