Implement get_serializer in generic list view (generics.ListCreateAPIView) in Django REST Framework -


i have pageserializer inherits dynamicfieldsmodelserializer copied docs (http://django-rest-framework.org/api-guide/serializers.html#dynamically-modifiying-fields). initialize serializer generic view implemented get_serializer. detail view (which inherits generics.retrieveupdatedestroyapiview) works fine, when try initialize pageserializer in list view (which inherits generics.retrieveupdatedestroyapiview) following error:

'pagelist' should either include 'serializer_class' attribute, or use 'model' attribute shortcut automatically generating serializer class. 

here's get_serializer implementation (which implemented in list view in detail view)

def get_serializer(self, instance=none, data=none, files=none, many=false, partial=false):     fields = none     if self.request.method == 'get':         query_fields = self.request.query_params.get("fields", none)          if query_fields:             fields = tuple(query_fields.split(','))      return pageserializer(instance=instance, data=data, files=files, many=many, partial=partial, fields=fields)  

judging error message get_serializer doesn't seem go used. there different way achieve list view? haven't managed find hints how get_serializer should used.

the error seeing because didn't declare serializer_class or model attribute on view. if don't specify must override get_serializer_class() tell view serializer use.

also said:

but when try initialize pageserializer in list view (which inherits generics.retrieveupdatedestroyapiview) following error:

a list view should inherit 1 of generic list views listcreateapiview, not single object view retrieveupdatedestroyapiview.


Comments