[Answered ]-Django Relationship Name Collisions โ€“ Abstract Model has multiple relationships with another Model

2๐Ÿ‘

โœ…

You have to make the related name unique. As stated in the docs you can add %(class)s or %(app_label)s. These are then replaced by the child class values:

class Topic(Model):
    name = CharField(max_length = 100)

    class Response(Model):
        body    = TextField()
        topics  = ManyToManyField(Topic)
        agreers = ManyToManyField(User)

        proposal = TextField()
        affirms  = ManyToManyField(User, related_name = '%(app_label)s_%(class)saffirmers')
        rejects  = ManyToManyField(User, related_name = '%(app_label)s_%(class)srejectors')

        class Meta:
            abstract = True

    class TopicResponse(Response):
        responseTo = ForeignKey(Topic, on_delete = CASCADE)

    class ResponseResponse(Response):
        responseTo = ForeignKey(Response, on_delete = CASCADE)
๐Ÿ‘คilse2005

Leave a comment