mercredi 28 janvier 2015

How can i combine both ListCreateAPIView and RetrieveUpdateDestroyAPIView in django into a single view that supports all four CRUD operations?

I am wondering how can i get a single point which can handle all operation for a model. And Why django doesn't have a generic for it in first place? I think its pretty common with other frameworks.



class ItemView(ListCreateAPIView, RetrieveUpdateDestroyAPIView):
"""
List all items(GET without id), List single item(GET with id),
create an item(POST) or update an item(PUT with id)
"""


This view class should return list of items on plain GET request and particular item if id is specified. Similarly, update and delete specific item only if id is present.





Aucun commentaire:

Enregistrer un commentaire