[Fixed]-How to specify uniqueness for a tuple of field in a Django model

42👍

There is a META option called unique_together. For example:

class MyModel(models.Model):
    field1 = models.BlahField()
    field2 = models.FooField()
    field3 = models.BazField()

    class Meta:
        unique_together = ("field1", "field2")

More info on the Django documentation page.

Leave a comment