Skip to content

Commit 1da1a59

Browse files
author
Jan Schrewe
committed
Fix file upload field if form edited and no files uploaded
1 parent b31830f commit 1da1a59

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

mongodbforms/documents.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,15 @@ def construct_instance(form, instance, fields=None, exclude=None, ignore=None):
6363
for f in file_field_list:
6464
upload = cleaned_data[f.name]
6565
field = getattr(instance, f.name)
66-
filename = _get_unique_filename(upload.name)
67-
upload.file.seek(0)
68-
field.replace(upload, content_type=upload.content_type, filename=filename)
69-
setattr(instance, f.name, field)
66+
try:
67+
upload.file.seek(0)
68+
filename = _get_unique_filename(upload.name)
69+
field.replace(upload, content_type=upload.content_type, filename=filename)
70+
setattr(instance, f.name, field)
71+
except AttributeError:
72+
# we should only reach here if there is already a file uploaded
73+
# and the form is edited again. So we do nothing.
74+
pass
7075

7176
return instance
7277

0 commit comments

Comments
 (0)