make value of two tables unique django 1

make value of two tables unique django

class MyModel(models.Model):
  field1 = models.CharField(max_length=50)
  field2 = models.CharField(max_length=50)

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

Here is what the above code is Doing:
1. It’s creating a model called MyModel.
2. It’s creating two fields, field1 and field2.
3. It’s telling Django that the combination of field1 and field2 must be unique.

Similar Posts