【发布时间】:2012-02-02 15:08:53
【问题描述】:
我正在尝试使用 Ajax/POST 对模型进行更新。我希望能够只发送正在更新的字段,而不是表单中的所有字段。但这似乎导致表单无效。有什么好办法吗?
例如:
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'}
同样用于更新类型。
有什么好办法吗?
【问题讨论】:
标签: django django-models django-forms django-class-based-views