I've created below models as a working solution for an app where I need multiple unique combinations of A and B in C:
class A(models.Model):
title = models.CharField(max_length=30)
class B(models.Model):
title = models.CharField(max_length=255)
a = models.ManyToManyField(A)
class C(models.Model):
title = models.CharField()
property1 = models.CharField()
class A_B_C(models.Model):
a = models.ForeignKey(A)
b = models.ForeignKey(B)
c = models.ForeignKey(C)
class Meta:
unique_together = ('a', 'b', 'c')
I was avoiding to create A_B_C explicitly and maintain it within relations. I would like to know if this solution would be efficient or is there another Django way to do things?