I am using formset and allowing users to upload multiple images. It worked. But the problem is if the user is not choosing any pics for upload, then the following code is saving submitter. If the user is not uploading any image, then I don’t want to save submitter. Is this possible?
if form.is_valid() and formset.is_valid():
for image_form in formset:
pics = image_form.save(commit=False)
pics_image.submitter = request.user
pics_image.save()
formset.save()does more processing than simply iterating on forms to save them.Thus you’ll need to check
form.has_changed()manually.Or rely on
formset.save(commit=False)which return instances to save