1
Well, I’m messing with an API and I want it to return content only when the user sector is equal to the publishing sector
API for publications:
The user has a sector field also equal to this, and I’m already able to get the current user’s industry id, but I can’t get the publication’s industry id to test!
py views.
class PostDetailAPIView(RetrieveAPIView):
queryset = Post.objects.all()
serializer_class = PostSerializer
def get_queryset(self):
queryset = Post.objects.all()
user_sector = None
if self.request.user.is_authenticated():
user_sector = self.request.user.sector.id
if user_sector is ...:
return queryset
remembering that I want to return to queryset every time the sector of some publication is equal to the sector of the logged in user!! help me in this
Try to use the self.get_object() that it returns the object of the current detail view, so you can do: post.sector and so do the verification with the user’s.
– Marlysson
I need to pass the sector as a parameter ?
– Guilherme Henrique
gave this error now 'Maximum recursion Depth exceeded'
– Guilherme Henrique
Not necessarily.. Take quetyset out of get_queryset.. Try using get_object inside get_queryset
– Marlysson