vintasoftware / drf-rw-serializers

Generic views, viewsets and mixins that extend the Django REST Framework ones adding separated serializers for read and write operations
MIT License
177 stars 28 forks source link

when i use Read & Write Serializers #7

Closed modekano closed 4 years ago

modekano commented 5 years ago

Description

Describe what you were trying to get done. Tell us what happened, what went wrong, and what you expected to happen.

What I Did

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.
modekano commented 5 years ago

when i used Read & Write Serializers as below: serializers:


class CashOutInReaderSerializer(serializers.ModelSerializer):
    class Meta:
        model = CashOutIn
        fields = ('id', 'amount', 'currency', 'note','customer' ,'created_at', 'is_transfer')
        depth=1

class CashOutInWriteSerializer(serializers.ModelSerializer):
    class Meta:
        model = CashOutIn
        fields = ('id', 'amount', 'currency', 'note','customer' ,'created_at', 'is_transfer')``

views:

class CashOutInView(generics.ListCreateAPIView):
    queryset = CashOutIn.objects.all()
    write_serializer_class = CashOutInWriteSerializer
    read_serializer_class = CashOutInReaderSerializer

i get this error:

  File "D:\django\mproject\transfer\transfers\urls.py", line 14, in <module>
    path('', include(router.urls))
  File "C:\Users\FIRSTT~1\Envs\transfer\lib\site-packages\rest_framework\routers.py", line 125, in urls
    self._urls = self.get_urls()
  File "C:\Users\FIRSTT~1\Envs\transfer\lib\site-packages\rest_framework\routers.py", line 386, in get_urls
    urls = super(DefaultRouter, self).get_urls()
  File "C:\Users\FIRSTT~1\Envs\transfer\lib\site-packages\rest_framework\routers.py", line 284, in get_urls
    routes = self.get_routes(viewset)
  File "C:\Users\FIRSTT~1\Envs\transfer\lib\site-packages\rest_framework\routers.py", line 200, in get_routes
    extra_actions = viewset.get_extra_actions()
AttributeError: type object 'CashOutInView' has no attribute 'get_extra_actions'
amitgaru2 commented 5 years ago

Please paste your urls.py code. I think you used router for ListCreateAPIView, router is only used for viewset inherited classes.

amitgaru2 commented 5 years ago

Find the examples and explanations here

  1. https://www.django-rest-framework.org/api-guide/generic-views/#examples
  2. https://www.django-rest-framework.org/api-guide/routers/#usage