I want to be able to make a model unique on a value that comes from a foreign key model. Not sure if that's possible in django.
Example: I have a model A as:
class modelA(models.Model):
fieldA1 = models.AutoField(primary_key=True)
fieldA2 = models.CharField(max_length=20)
And also model B as:
class modelB(models.Model):
fieldB1 = models.CharField(max_length=20)
fieldB2 = models.ForeignKey(modelA)
class Meta:
unique_together = ('fieldB1', 'fieldB2',<<'fieldA2'>>)
I want to add fieldA2 as one of the attributes in the unique_together clause of model B. Is that possible in Django? I COULD NOT do it as-
unique_together = ('fieldB1', 'fieldB2','modelA__fieldA2')