Multi-Value Primary Keys in Django
I need to enforce a property in a model such that for each 'User' field in this particular table, it's corresponding 'Post' field is distinct - and vice versa (i.e., for each particular 'Post' field, the corresponding 'User' field is distinct). I'm not sure how to do this in Django. I think one approach would be to define the ('User', 'Post') tuple to be a primary key, but it doesn't seem that Django supports this. Is there any other 开发者_如何学编程way to enforce this constraint at the field specifications of a Django model (i.e., without doing all the checks in a save() function)? Thanks, appreciate any feedback!
You can use unique-together in the Meta
class.
精彩评论