我想在django中实现多列主键。
我试图实现一个AutoSlugField(),它连接我的列值(foreignkey / dates)......
models.py:
class ProductProduction(models.Model):
enterprise = models.ForeignKey('Enterprise')
product = models.ForeignKey('Product')
date = models.DateTimeField()
count = models.IntegerField()
slug = AutoSlugField(populate_from=
lambda instance: instance.enterprise.username + '-' + instance.product.name + '-' + str(date))
当我传递以下参数时:
- 'Megacorp','robot','09/10/2010',5 => slug = 'Megacorp-robot-09/10/2010'
... the next time in pass the triplet, a new value has been inserted :
- 'Megacorp','robot','09/10/2010',10 => slug = 'Megacorp-robot-09/10/2010'
=> same slug value => insert ????
我尝试将primary_key=True
参数添加到slug中......但它创建了一个带有“-1”“-2”的新实例......并且根本没有更新...
我错过了什么吗?
谢谢,
Yoan
答案 0 :(得分:0)