【发布时间】:2018-10-05 10:26:44
【问题描述】:
我想根据我数据库中的项目数设置uuid。
class Order(Document):
uuid = None
def __init__(self):
self.uuid = self.gen_uuid()
def gen_uuid(self):
date = datetime.now().strftime('%d%m%y')
count = self.objects.count()
return date + str(count)
不幸的是,引用self.objects.count() 抛出AttributeError: 'QuerySetManager' object has no attribute 'count。
我很困惑,因为这是访问模型数据的 API 方式。因此,我的问题是,在模型定义中引用模型数据的正确方法是什么?
【问题讨论】:
标签: python mongoengine