質問

私は、いくつかの分野で1つのモデルしかない非常に単純なアプリケーションに取り組んでいます。これらのモデルは、/管理ページ(標準のDjango管理フレームワークを介して)を介してのみ作成または削除され、REST APIフレームワークがこれらのオブジェクトのみを変更できるようにします。

それを起こす簡単な方法はありますか?

役に立ちましたか?

解決

以下のものと同じhttp_method_namesを設定する必要があります。

class WebViewSet(mixins.CreateModelMixin,
                 mixins.ListModelMixin,
                 mixins.UpdateModelMixin,
                 viewsets.GenericViewSet):

    model = WebTransaction
    http_method_names = ('get', 'put')
.

他のヒント

UPDATE / RETRIEVE MODE MIXENを使用するビューセットを作成します。

from rest_framwork import viewsets, mixins
class FooViewSet(mixens.RetrieveModelMixin,
                 mixins.UpdateModelMixin,
                 viewsets.GenericViewSet):
    model = Foo
    queryset = Foo.objects.all()
    serializer_class = FooSerializer
.

これはあなたのモデルのインスタンスを取得または更新するためのApiendポイントするだけです。

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top