Answer the question
In order to leave comments, you need to log in
Designing a Follower/Following Model in Django. Which option to choose?
I am writing another service for working with social networks. I thought about implementing the follower model.
In principle, Google gives out a lot of options, since the topic is already beaten up enough.
The following torments me: in addition to the usual Follower / Followed by relationship, others must be implemented, like: Blocked / Blocked by, Track / Tracked by, Competitor, etc.
So far I see 2 scenarios:
class SMMProfile(models.Model):
username = models.CharField("Username")
follows = models.ManyToManyField("self", related_name = 'followed_by')
blocks = models.ManyToManyField("self", related_name = 'blocked_by')
tracks = models.ManyToManyField("self", related_name = 'tracked_by')
class SMMProfile(models.Model):
username = models.CharField("Username")
relations = models.ManyToManyField('self', symmetrical=False, through='Relationship')
class Relationship(models.Model):
TYPE_CHOICES = (
(0, "Follow"),
(1, "Block"),
(2, "Track"))
who = models.ForeignKey(SMMProfile, related_name="who")
whom = models.ForeignKey(SMMProfile, related_name="whom")
type = models.PositiveIntegerField("Type", choices=TYPE_CHOICES)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question