[Django]-Django: correct order of these models

3👍

You can always use a string in such cases:

class A(models.Model):
    #some details
    pass


class B(models.Model):
    a = models.ForeignKey("A", null=True, blank=True) # note the quotes
    c = models.ForeignKey("C", null=True, blank=True) # note the quotes

class C(models.Model):
    pass

If this was a more “extreme” case and you couldn’t use this trick, declaring C first, then A and B, and after that C.method (def C_method [...] C.method = C_method) would have been the way to follow.

Leave a comment