Reputation: 3
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?
Upvotes: 0
Views: 573
Reputation: 5888
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.
Upvotes: 1