M
M
merzlyakovme2017-06-06 20:22:06
Django
merzlyakovme, 2017-06-06 20:22:06

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')

either such
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

1 answer(s)
S
sim3x, 2017-06-06
@sim3x

The first one is obviously easier to use.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question