Django REST Updateview with PUT POST

南笙酒味 提交于 2019-12-24 16:44:14

问题


Within a listview, with many objects, I want to change their value live by javascript, then save them by a POST/PUT http request to the object updateview, searching I've found that it maybe possible with Django REST framework.

I've read the Django REST framework manual reference

but didn't understand how to set up the UpdateView call:

model.py

class presetrows(models.Model):
    progressivo = models.ForeignKey(preset)
    value = models.BigIntegerField(blank=True, null=True) 

views.py

class RighePresetListView(ListView):
    queryset = presetrows.objects.filter(stato=True)

class RighePresetUpdateView(UpdateView):
    model = presetrows
    exclude=()

but where should I add the update(request, *args, **kwargs) from django REST?


回答1:


You don't really needs to define update(request, *args, **kwargs) in DRF views. For update api you can use this

class RighePresetUpdateView(UpdateAPIView):

    serializer_class = 'your serializer'
    queryset = presetrows.objects.filter(stato=True)

Provides put and patch method handlers implicitly.



来源:https://stackoverflow.com/questions/32014664/django-rest-updateview-with-put-post

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!