Django complex relationship

7 views
Skip to first unread message

rak...@stylabs.in

unread,
Jan 15, 2016, 4:27:48 AM1/15/16
to Django users

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?

Reply all
Reply to author
Forward
0 new messages