带PUT POST的Django REST Updateview [英] Django REST Updateview with PUT POST
问题描述
在 listview 中,有许多对象,我想通过javascript实时更改其值,然后通过POST / PUT http请求将其保存到对象 updateview ,搜索我发现使用Django REST框架可能是可行的。
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.
我已阅读Django REST框架
手册参考
I've read the Django REST framework manual reference
但没有不了解如何设置UpdateView调用:
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=()
但是我应该在哪里添加更新(请求,* args,** kwargs)来自Django REST?
but where should I add the update(request, *args, **kwargs) from django REST?
推荐答案
您实际上不需要定义 update(request,* args, ** kwargs)
在DRF视图中。对于更新API,您可以使用此
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.
这篇关于带PUT POST的Django REST Updateview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!