Skip to content

Commit 26f656b

Browse files
author
Jan Schrewe
committed
Data and files argument before instance or position for EmbeddedDocumentForms.
Should avoid the problems in jschrewe#50
1 parent ff22563 commit 26f656b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

mongodbforms/documents.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,12 +530,14 @@ def documentform_factory(document, form=DocumentForm, fields=None, exclude=None,
530530

531531

532532
class EmbeddedDocumentForm(with_metaclass(DocumentFormMetaclass, BaseDocumentForm)):
533-
534-
def __init__(self, parent_document, instance=None, position=None, *args, **kwargs):
533+
534+
def __init__(self, parent_document, data=None, files=None, position=None, *args, **kwargs):
535535
if self._meta.embedded_field is not None and not \
536536
self._meta.embedded_field in parent_document._fields:
537537
raise FieldError("Parent document must have field %s" % self._meta.embedded_field)
538538

539+
instance = kwargs.get('instance', None)
540+
539541
if isinstance(parent_document._fields.get(self._meta.embedded_field), ListField):
540542
# if we received a list position of the instance and no instance
541543
# load the instance from the parent document and proceed as normal
@@ -549,7 +551,7 @@ def __init__(self, parent_document, instance=None, position=None, *args, **kwarg
549551
emb_list = getattr(parent_document, self._meta.embedded_field)
550552
position = next((i for i, obj in enumerate(emb_list) if obj == instance), None)
551553

552-
super(EmbeddedDocumentForm, self).__init__(instance=instance, *args, **kwargs)
554+
super(EmbeddedDocumentForm, self).__init__(data=data, files=files, instance=instance, *args, **kwargs)
553555
self.parent_document = parent_document
554556
self.position = position
555557

0 commit comments

Comments
 (0)