django-viewsets

How to get the authentication information in ModelViewSet?

How to get the authentication information in ModelViewSet? Question: I am using rest framework with ModelViewSet class DrawingViewSet(viewsets.ModelViewSet): queryset = m.Drawing.objects.all() serializer_class = s.DrawingSerializer filterset_fields = [‘user’] def list(self, request): queryset = m.Drawing.objects.all() serializer = s.DrawingSerializer(queryset, many=True) return Response(serializer.data) With this script, I can use filter such as /?user=1 Howver this user=1 is not necesary …

Total answers: 2

ViewSet class variable

ViewSet class variable Question: Now I have the following logic implemented for a GET request in Django Rest Framework: class SomeViewSet(mixins.ListModelMixin, GenericViewSet): count = None def get_queryset(self): query_set = … # some_logic self.count = query_set.count() return query_set def list(self, request, *args, **kwargs): response = super().list(request, *args, **kwargs) response.data = {‘count’: self.count, ‘data’: response.data} return response …

Total answers: 1

How can i set pagination dynamically in Django Rest Framework?

How can i set pagination dynamically in Django Rest Framework? Question: I made an API endpoint using Django Rest Framework, it can be filtered according to two parameters. I’m trying to do the following: when there is no filter, it should retrieve x number of records, while when there is one or more filter, it …

Total answers: 2