[Fixed]-Django follower structure with manytomany field unable to display in Admin

1πŸ‘

βœ…

To display a human-readable representation you should write a __str__ (if using python2 the name should be __unicode__) method on the model. Django admin will use this method to display the instances, you don’t need to override or customize anything in admin.py for this.

In your case, like this:

class SocialProfile(models.Model):
    user = models.OneToOneField(User, unique=True)
    follows = models.ManyToManyField('self', related_name='followed_by', symmetrical=False)

    def __str__(self):
        """Return human-readable representation"""
        return self.user.username
πŸ‘€danielcorreia

Leave a comment