开发者

Need two fields together to be unique

Say I have a model like this:

class Book(models.Model):

    user = models.ForeignKey(User)
    book_isbn = models.CharField()

I would like the combination of the book and user fields to be unique. That is different users could have the same book, but a specific user could only have the book once in their list of books.

开发者_运维百科

I thought unique_together would be the perfect solution, but them read it can't be used if any of the fields have a FK. What's the best way to achieve what I want?


I'm currently using multiple django models with unique_together clause which contained foreign keys and I never had any problems. I currently using django 1.2.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜