timeline_aggregated 被关注的用户为空
timeline_aggregated empty for a user that get followed
基本上我有这个型号:
# models.py
class Follow(Activity, models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='friends')
target = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='followers')
created_at = models.DateTimeField(auto_now_add=True)
class Meta:
unique_together = ('user', 'target', )
def __str__(self):
return '{0} follows {1}'.format(self.user, self.target)
@property
def extra_activity_data(self):
return {'username': self.user.username}
@classmethod
def activity_related_models(cls):
return ['user', 'target']
@property
def activity_notify(self):
if not settings.STREAM_DISABLE_MODEL_TRACKING:
# Another example would be following a user. You would commonly want to notify the user which is being
# followed.
return [feed_manager.get_notification_feed(self.target_id)]
@receiver(post_delete, sender=Follow)
def unfollow_user_feed(sender, instance, **kwargs):
if not settings.STREAM_DISABLE_MODEL_TRACKING:
feed_manager.unfollow_user(instance.user_id, instance.target_id)
@receiver(post_save, sender=Follow)
def follow_user_feed(sender, instance, created, **kwargs):
if created and not settings.STREAM_DISABLE_MODEL_TRACKING:
feed_manager.follow_user(instance.user_id, instance.target_id)
一个简单的工作流程可以是
<load gab and freddy user instances>
Follow.objects.create(user=gab, target=freddy) # gab follows freddy
在供稿 user:freddy.id
的 GetStream 仪表板中,我看到有 2 个关注者 timeline_aggregated:gab.id
和 timeline:gab.id
。
现在,如果我加载 freddy 的 timeline_aggregated:
feed_manager.get_feed('timeline_aggregated', freddy.id)
activities = self.feed.get(limit=self.page_size)['results']
它不包含 "gab follows freddy" 的引用,因此 activities
是 {}
,而我希望包含它。
我错了吗?
谢谢,
D
保存关注模型后,将创建一个 activity 并将其添加到关注者的用户供稿中,并将副本发送到目标的通知供稿中(参见 Follow.activity_notify
)。
根据您的示例,activity "gab follows freddy" 应该在这两个 Feed 中:"user:bag" 和 "notification:freddy"。
基本上我有这个型号:
# models.py
class Follow(Activity, models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='friends')
target = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='followers')
created_at = models.DateTimeField(auto_now_add=True)
class Meta:
unique_together = ('user', 'target', )
def __str__(self):
return '{0} follows {1}'.format(self.user, self.target)
@property
def extra_activity_data(self):
return {'username': self.user.username}
@classmethod
def activity_related_models(cls):
return ['user', 'target']
@property
def activity_notify(self):
if not settings.STREAM_DISABLE_MODEL_TRACKING:
# Another example would be following a user. You would commonly want to notify the user which is being
# followed.
return [feed_manager.get_notification_feed(self.target_id)]
@receiver(post_delete, sender=Follow)
def unfollow_user_feed(sender, instance, **kwargs):
if not settings.STREAM_DISABLE_MODEL_TRACKING:
feed_manager.unfollow_user(instance.user_id, instance.target_id)
@receiver(post_save, sender=Follow)
def follow_user_feed(sender, instance, created, **kwargs):
if created and not settings.STREAM_DISABLE_MODEL_TRACKING:
feed_manager.follow_user(instance.user_id, instance.target_id)
一个简单的工作流程可以是
<load gab and freddy user instances>
Follow.objects.create(user=gab, target=freddy) # gab follows freddy
在供稿 user:freddy.id
的 GetStream 仪表板中,我看到有 2 个关注者 timeline_aggregated:gab.id
和 timeline:gab.id
。
现在,如果我加载 freddy 的 timeline_aggregated:
feed_manager.get_feed('timeline_aggregated', freddy.id)
activities = self.feed.get(limit=self.page_size)['results']
它不包含 "gab follows freddy" 的引用,因此 activities
是 {}
,而我希望包含它。
我错了吗?
谢谢,
D
保存关注模型后,将创建一个 activity 并将其添加到关注者的用户供稿中,并将副本发送到目标的通知供稿中(参见 Follow.activity_notify
)。
根据您的示例,activity "gab follows freddy" 应该在这两个 Feed 中:"user:bag" 和 "notification:freddy"。