Django reverse Accessor Clash – Related Name not working

I am receiving an error for ‘reverse accessor’ clashes when trying to create a models for my Django app. Based on what I have seen, supposedly, assigning a unique ‘related name’ to the fields solve the issue. However, I have tried this and it still occurs.

I have also tried using '%(app_label)s_%(class)s_related' as a related name as well, but this has not worked.

I am struggling a bit to understand how this all works – is anyone able to help me out?

Will provide code below, thanks

class TradeOffersManager(models.Manager):
    def create_trade_offer(self, sender, reciever, sending_item, recieving_item):
        trade_offer = self.create(sending_item=sending_item, recieving_item=recieving_item)
        trade_offer.sender.set(sender)
        trade_offer.reciever.set(reciever)
        return trade_offer

class TradeOffers(models.Model):
    sender = models.ManyToManyField(User)
    sending_item = models.ForeignKey(TradePost, on_delete=models.CASCADE, related_name="sending_item_name")

    reciever = models.ManyToManyField(User)
    recieving_item = models.ForeignKey(TradePost, on_delete=models.CASCADE, related_name="recieving_item_name")

    objects = TradeOffersManager()

I have figured this out – it turns out it didn’t like the name I have chose ‘sending_item_name’.. I think maybe its the ‘name’ part but not 100% sure. I have changed this now to just ‘sending_item’ and it is working.

Leave a Comment