I have the following form:
class PostForm(forms.ModelForm):
class Meta:
model = Post
fields = ['title', 'main_image', 'related_to']
post method in views class
def post(self, request, pk):
form=PostForm(instance=self.post,data=request.POST,files=request.FILES)
if form.is_valid():
form.save()
else:
print(form.errors)
return redirect('post_detail_change', self.post.id)
and in template
<form action="" method="post" enctype="multipart/form-data">
{{contact.title}}
{% csrf_token %}
</form>
<form action="" method="post" enctype="multipart/form-data">
{{contact.main_image}}
{% csrf_token %}
</form>
<form action="" method="post" enctype="multipart/form-data">
{{contact.related_to}}
{% csrf_token %}
</form>
and i have a js code that sends a post request when any of the 3 forms are changed.
for (let i=0; i < forms.length; i++) {
forms[i].addEventListener('change', function (e) {
this.submit()
})
}
So, my problem is that i trying to save, for example, ‘main_image’ field, it fails because it reques ‘title’ field. How can i handle it?