我需要将 UUID 实现为主键,但我不确定如何在 Django 中实现。
我的代码
class LinkRenewAd(models.Model): # This model will generate the uuid for the ad renew link
def make_uuid(self):
return str(uuid.uuid1().int>>64)
uuid = models.CharField(max_length=36, primary_key=True, default=make_uuid, editable=False)
main = models.ForeignKey(Main)
expiration_date = models.DateTimeField()
date_inserted = models.DateTimeField(auto_now_add=True)
date_last_update = models.DateTimeField(auto_now=True)
当我尝试在 South 上生成这个新模型时,我得到了错误:
TypeError: make_uuid() takes exactly 1 argument (0 given)