43👍
✅
I’ve found the solution
class UserPostsReadView(generics.ListAPIView):
serializer_class = PostSerializer
model = serializer_class.Meta.model
paginate_by = 100
def get_queryset(self):
poster_id = self.kwargs['poster_id']
queryset = self.model.objects.filter(poster_id=poster_id)
return queryset.order_by('-post_time')
Source: http://www.django-rest-framework.org/api-guide/filtering/#filtering-against-the-url
4👍
I know is late for this, but I wrote a little app that extends for ListAPIView and do this easier, check it out:
- [Django]-How to display all model fields with ModelSerializer?
- [Django]-Django QueryDict only returns the last value of a list
- [Django]-How do I get Django Admin to delete files when I remove an object from the database/model?
Source:stackexchange.com