I’m trying to make updates to a model using Ajax/POST. I’d like to be able to just send the field being updated and not all fields in the Form. But this seems to cause the form to be invalid. Is there a good way to do this?
eg:
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
When updating the name I’d like to send a POST with this data
{'name': 'new name'}
as opposed to
{'name': 'new name', 'type':'existing type', 'owner': 'current owner'}
And likewise for updating type.
Is there a good way to do this?
Why don’t you simply create a form — say,
AjaxUpdateNameForm— and then use django-ajax-validation to handle ajax requests?