Hey!

Is there any way to generalize ViewSets?

class ResidentViewSet(viewsets.ModelViewSet):
queryset = Resident.objects.all()
serializer_class = ResidentSerializer

class RoomViewSet(viewsets.ModelViewSet):
queryset = Room.objects.all()
serializer_class = RoomSerializer


I tried to do it in a simple way, but it seems like routers use it someway 
that disable creation of instances. I guess there is a reason behind this 
but can't work around it. I want to create many API routes and making every 
single serializer/viewSet which are the same will be a really boring job.


class CommonViewSet(viewsets.ModelViewSet):
serializer_class = None
queryset = None

def __init__(self, model):
self.queryset = model.objects.all()
self.serializer_class = CommonSerializer(model)

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to