[Django]-Unique foreign key pairs with Django

34👍

Use unique_together to make sure that each user/product combination is unique:

class Review(models.Model):

  class Meta:

    unique_together = ['user', 'product']

  user = models.ForeignKey(User)
  product = models.ForeignKey(Product)

Leave a comment