Reputation: 6740
I am working on a very simple application that has only 1 model with a couple of fields. I want these models to be created or deleted only through the /admin pages (through the standard Django admin framework) and allow the rest api framework to only alter these objects.
Is there any simple way to make it happen?
Upvotes: 0
Views: 1572
Reputation: 5949
You need set up http_method_names
same as below:
class WebViewSet(mixins.CreateModelMixin,
mixins.ListModelMixin,
mixins.UpdateModelMixin,
viewsets.GenericViewSet):
model = WebTransaction
http_method_names = ('get', 'put')
Upvotes: 3
Reputation: 344
If you want just update the objects use UpdateApiView. With this view you will create just the update(PUT Method) for you model.Any doubts follow the documentation in Documentation DRF.
Upvotes: 0
Reputation: 7064
Just create a viewset that uses update/retrieve model mixen.
from rest_framwork import viewsets, mixins
class FooViewSet(mixens.RetrieveModelMixin,
mixins.UpdateModelMixin,
viewsets.GenericViewSet):
model = Foo
queryset = Foo.objects.all()
serializer_class = FooSerializer
This will only give you an APIEnd points to retrieve or update an instance of your model.
Upvotes: 2