开发者

Django - Multiple columns primary key

I would like to implement multicolumns primary keys in django.

I've tried to implement an AutoSlugField() which concatenate my columns values(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))

When I pass the following parameters :

 - '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 ????

I tried to add prim开发者_高级运维ary_key=True parameter to the slug... but it creates new instance with a "-1" "-2" ... and NO update is made at all...

Did I miss something ?

Thanks,

Yoan


Here is the explanation of the autoslugfield I used.

http://packages.python.org/django-autoslug/fields.html

Regards,

Yoan

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜