How can I organize a relationship system in django? I need the ability to add / remove from friends, accept / reject an application for friends and the like, but I can’t imagine using what means to accomplish this. just learning

  • 2
    Well, you're a villain! hashcode.ru/questions/132056/… - qnub
  • Yes, villain. But I am still interested in what fields this can be achieved in a separate class or within the user. In a word, I need architecture and a kick in the right direction - LiGhT_WoLF
  • The author apparently accidentally poked in the past question at the correct answer, without really getting an answer. - rnd_d
  • Yes, something like that. There I was more interested in whether there are ready-made solutions. - LiGhT_WoLF

1 answer 1

First, determine how much functionality you need in the relationship system, if the full functionality is like in VK (friends, requests, subscriptions), then you need three models of this type:

class Subscribe(models.Model): from_user = models.ForeignKey('auth.User') to_user = models.ForeignKey('auth.User', related_name="person_subscribers") class Friendship(models.Model): to_user = models.ForeignKey('auth.User', related_name="friends") from_user = models.ForeignKey('auth.User') class FriendshipRequest(models.Model): to_user = models.ForeignKey('auth.User', related_name="friendship_requests_to") from_user = models.ForeignKey('auth.User', related_name="friendship_requests_from") status = models.CharField(max_length=25, choices=REQUEST_STATUS, default=CREATED) 

They are still managers with a bunch of methods, if without subscribers, then it is already easier.

  • So already interesting. Subscriptions just will not. Thanks for the advice - LiGhT_WoLF