我一直在使用django-relationships来允许用户互相关注。如果鲍勃跟随乔。Bob 将能够看到 Joe 的所有照片。但是,如果 Bob 屏蔽了 John,John 将不是 Bob 的照片。
我的问题是我不知道如何限制来自被阻止用户的内容。我已经看过这些例子,但我似乎仍然找不到解决方案。
假设摄影师是用户的 FK
这是我的 FollowPhoto 资源(此资源返回属于用户关注的人的所有照片):
FollowingPhoto(ModelResource):
photographer = fields.ForeignKey(PhotographerResource, 'photographer', full=True)
class Meta:
queryset = Photo.objects.all().order_by('-postTime')
resource_name = 'following'
fields = ['id', 'title', 'url', 'likes','postTime','photographer', 'location_id', 'location_name']
authentication = BasicAuthentication()
authorization = DjangoAuthorization()
serializer = Serializer(formats=['json'])
include_resource_uri = False
filtering = {
'postTime': ALL,
'photographer' : ALL_WITH_RELATIONS,
}
def get_object_list(self, request):
return super(FollowingPhoto, self).get_object_list(request).filter(photographer__user__in = request.user.relationships.following())
现在,您可能已经注意到我的 get_object_list,它返回了我关注的用户的所有内容。如何防止被阻止的用户出现在此列表中?
Django-relationships 应用程序在 postgresql 中生成两个表,下表是关系关系表:
id from_user to_user_id status_id created
[PK] serial integer integer timestamp
6 1 5 1 2012-10-05 20:10:29.848667+00"
7 1 3 1 2012-10-05 20:11:23.319961+00"
另一个表是关系关系状态表:
id name verb from_slug login_required private
[PK] serial character character character varying boolean boolean
1 Following follow friends FALSE FALSE
2 Blocking block ! TRUE TRUE
下面我添加了一个指向 Django-relationships models.py 的链接,以便您进一步了解: