I am not a DRF expert but it looks like that should work. Would you mind 
providing a bit more information?

Is get_serializer_class() called? Or is it never even called?

On Friday, November 22, 2019 at 12:21:44 PM UTC+11, Cristian Benavides 
Jimenez wrote:
>
> 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/bac1ec45-bdd2-4acb-a49a-5e982840d5b0%40googlegroups.com.

Reply via email to