我想使用Ajax/POST对模型进行更新。我希望能够发送正在更新的字段,而不是表单中的所有字段。但是这似乎导致表单无效。有没有一个好的方法来做到这一点?Ajax和ModelForm更新模型
如:
class Video(models.Model):
name = models.CharField(max_length=100)
type = models.CharField(max_length=100)
owner = models.ForeignKey(User, related_name='videos')
...
#Related m2m fields
....
class VideoForm(modelForm):
class Meta:
model = Video
fields = ('name', 'type', 'owner')
class VideoCreate(CreateView):
template_name = 'video_form.html'
form_class = VideoForm
model = Video
当更新的名字,我想发送POST与此数据
{'name': 'new name'}
,而不是
{'name': 'new name', 'type':'existing type', 'owner': 'current owner'}
27:11更新类型。
有没有很好的方法来做到这一点?