mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-24 00:04:16 +03:00
Split concrete generic views up into separate bits of functionality
This commit is contained in:
parent
9a741e7ddb
commit
32ebf96ef6
|
@ -95,6 +95,17 @@ class SingleObjectBaseView(SingleObjectMixin, BaseView):
|
||||||
### Concrete view classes that provide method handlers ###
|
### Concrete view classes that provide method handlers ###
|
||||||
### by composing the mixin classes with a base view. ###
|
### by composing the mixin classes with a base view. ###
|
||||||
|
|
||||||
|
|
||||||
|
class CreateAPIView(mixins.CreateModelMixin,
|
||||||
|
BaseView):
|
||||||
|
|
||||||
|
"""
|
||||||
|
Concrete view for creating a model instance.
|
||||||
|
"""
|
||||||
|
def post(self, request, *args, **kwargs):
|
||||||
|
return self.create(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class ListAPIView(mixins.ListModelMixin,
|
class ListAPIView(mixins.ListModelMixin,
|
||||||
MultipleObjectBaseView):
|
MultipleObjectBaseView):
|
||||||
"""
|
"""
|
||||||
|
@ -104,19 +115,6 @@ class ListAPIView(mixins.ListModelMixin,
|
||||||
return self.list(request, *args, **kwargs)
|
return self.list(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class ListCreateAPIView(mixins.ListModelMixin,
|
|
||||||
mixins.CreateModelMixin,
|
|
||||||
MultipleObjectBaseView):
|
|
||||||
"""
|
|
||||||
Concrete view for listing a queryset or creating a model instance.
|
|
||||||
"""
|
|
||||||
def get(self, request, *args, **kwargs):
|
|
||||||
return self.list(request, *args, **kwargs)
|
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
|
||||||
return self.create(request, *args, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
class RetrieveAPIView(mixins.RetrieveModelMixin,
|
class RetrieveAPIView(mixins.RetrieveModelMixin,
|
||||||
SingleObjectBaseView):
|
SingleObjectBaseView):
|
||||||
"""
|
"""
|
||||||
|
@ -126,31 +124,43 @@ class RetrieveAPIView(mixins.RetrieveModelMixin,
|
||||||
return self.retrieve(request, *args, **kwargs)
|
return self.retrieve(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class RetrieveDestroyAPIView(mixins.RetrieveModelMixin,
|
class DestroyAPIView(mixins.DestroyModelMixin,
|
||||||
mixins.DestroyModelMixin,
|
SingleObjectBaseView):
|
||||||
SingleObjectBaseView):
|
|
||||||
"""
|
|
||||||
Concrete view for retrieving or deleting a model instance.
|
|
||||||
"""
|
|
||||||
def get(self, request, *args, **kwargs):
|
|
||||||
return self.retrieve(request, *args, **kwargs)
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
Concrete view for deleting a model instance.
|
||||||
|
"""
|
||||||
def delete(self, request, *args, **kwargs):
|
def delete(self, request, *args, **kwargs):
|
||||||
return self.destroy(request, *args, **kwargs)
|
return self.destroy(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class RetrieveUpdateDestroyAPIView(mixins.RetrieveModelMixin,
|
class UpdateAPIView(mixins.UpdateModelMixin,
|
||||||
mixins.UpdateModelMixin,
|
SingleObjectBaseView):
|
||||||
mixins.DestroyModelMixin,
|
|
||||||
SingleObjectBaseView):
|
|
||||||
"""
|
|
||||||
Concrete view for retrieving, updating or deleting a model instance.
|
|
||||||
"""
|
|
||||||
def get(self, request, *args, **kwargs):
|
|
||||||
return self.retrieve(request, *args, **kwargs)
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
Concrete view for updating a model instance.
|
||||||
|
"""
|
||||||
def put(self, request, *args, **kwargs):
|
def put(self, request, *args, **kwargs):
|
||||||
return self.update(request, *args, **kwargs)
|
return self.update(request, *args, **kwargs)
|
||||||
|
|
||||||
def delete(self, request, *args, **kwargs):
|
|
||||||
return self.destroy(request, *args, **kwargs)
|
class ListCreateAPIView(ListAPIView,
|
||||||
|
CreateAPIView):
|
||||||
|
"""
|
||||||
|
Concrete view for listing a queryset or creating a model instance.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class RetrieveDestroyAPIView(RetrieveAPIView,
|
||||||
|
DestroyAPIView):
|
||||||
|
"""
|
||||||
|
Concrete view for retrieving or deleting a model instance.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class RetrieveUpdateDestroyAPIView(RetrieveAPIView,
|
||||||
|
UpdateAPIView,
|
||||||
|
DestroyAPIView):
|
||||||
|
"""
|
||||||
|
Concrete view for retrieving, updating or deleting a model instance.
|
||||||
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user