私は3つのモデルを持っています:
class UserProfile(models.Model):
slug = models.SlugField(max_length=200)
user = models.ForeignKey(User, unique =True)
relationships = models.ManyToManyField('self', through='Relationship',symmetrical=False,null=True, blank=True,related_name='related_to')
def get_relationships(self, status):
return self.relationships.filter(
to_people__status=status,
to_people__from_person=self)
def get_related_to(self, status):
return self.related_to.filter(
from_people__status=status,
from_people__to_person=self)
def get_following(self):
return self.get_relationships(RELATIONSHIP_FOLLOWING)
def get_followers(self):
return self.get_related_to(RELATIONSHIP_FOLLOWING)
class Relationship(models.Model):
from_person = models.ForeignKey(UserProfile, related_name='from_people')
to_person = models.ForeignKey(UserProfile, related_name='to_people')
status = models.IntegerField(choices=RELATIONSHIP_STATUSES)
class ActivityUser(models.Model):
slug = models.SlugField(max_length=200)
user = models.ForeignKey('UserProfile')
userB = models.ForeignKey('UserProfile', related_name='userFriend',null=True, blank=True)
status = models.IntegerField(choices=NOTIFICATION_STATUS)
date = models.DateTimeField(default=datetime.now)
基本的にユーザーは相互にフォローでき、ユーザーは活動を行うことができます。すべてのフォロワーとフォローからすべてのアクティビティを取得できるようにしたいと考えています。何か案が ?ありがとうございました