Hi,

Can you elaborate on the « don’t work » part ?
I have been using get_serializer_class and it has always worked well to me with 
GenericViewSet.

Regards,
Xavier O.
Linovia
Le 22 nov. 2019 à 02:22 +0100, Cristian Benavides Jimenez 
<sairok...@gmail.com>, a écrit :
> Hi everybody,
>
> I try use a two serializers in one view inherits from GenericViewSet with the 
> method get_serializer_class
>
> Here a little piece of my code:
>
> class RandomViewSet(ListModelMixin, GenericViewSet):
>    permission_classes = (IsAuthenticated, )
>    filter_backends = [filters.SearchFilter, filters.OrderingFilter, ]
>    search_fields = ['some_field', 'some_field', 'some_field', ]
>    ordering_fields = ['pk', ]
>    ordering = ['pk', ]
>    lookup_field = 'pk'
>    serializer_class = OneSerializer
>    serializers = {
>        'list': OneSerializer,
>        'create': TwoSerializer,
>    }
>
>    def get_serializer_class(self, *args, **kwargs):
>        print('THIS METHOD DON\'T WORK')
>        return self.serializers.get(self.action)
>
>    def create(self, request, *args, **kwargs):
>        print('Data is not validated :(')
>
>
>
> Any help for this?
>
> Greetings,
>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django REST framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-rest-framework+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-rest-framework/438adf7c-e2d5-480c-8716-9bd83116c902%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-rest-framework/ef9bd70c-9abf-4a79-a076-9d01779d843f%40Spark.

Reply via email to