django-mongodbforms icon indicating copy to clipboard operation
django-mongodbforms copied to clipboard

Django 1.9 incompatibility

Open fabian-marquardt opened this issue 9 years ago • 4 comments

Django 1.9 has been released recently. Using this version, django-mongodbforms fails to load with the following exception:

  File "/usr/lib/python3.5/site-packages/mongodbforms/documents.py", line 11, in <module>
    from django.forms.util import ErrorList
ImportError: No module named 'django.forms.util'

There is already a pull request to fix this issue. Please merge this code to the master branch.

fabian-marquardt avatar Dec 02 '15 15:12 fabian-marquardt

I've forked this project and released django-mongoengine-forms on PyPI. I've stripped out a lot of the legacy stuff and it should be compatible with Django 1.9.

If you find any issues I'd be very happy to hear them.

thomwiggers avatar Dec 13 '15 20:12 thomwiggers

nice @thomwiggers ! I was implementing the 1.9 compats but I'm gonna try to use your fork. We've developed a few useful features and fixes on our side, I might to a PR on your repo :)

m-vdb avatar Jan 05 '16 23:01 m-vdb

Following patch fixes a missing attribute new_objects error with django 1.8.8; I wrong put this into django-mongoadmin issues :( mea maxima culpa

diff --git a/mongodbforms/documents.py b/mongodbforms/documents.py index 0a432a8..0397c2d 100644 --- a/mongodbforms/documents.py +++ b/mongodbforms/documents.py ....... see below for structure version :( saved.append(obj)

replabrobin avatar Feb 02 '16 16:02 replabrobin

sorry that looks awful; I'm not a git person obviously :(, but maybe an old git :)

diff --git a/mongodbforms/documents.py b/mongodbforms/documents.py
index 0a432a8..0397c2d 100644
--- a/mongodbforms/documents.py
+++ b/mongodbforms/documents.py
@@ -703,9 +703,16 @@ class BaseDocumentFormSet(BaseFormSet):
         Saves model instances for every form, adding and changing instances
         as necessary, and returns the list of instances.
         """
+
         saved = []
+        self.new_objects = []
+        self.changed_objects = []
+        self.deleted_objects = []
+
         for form in self.forms:
-            if not form.has_changed() and form not in self.initial_forms:
+            changed = form.has_changed()
+            new = form not in self.initial_forms
+            if not changed and new:
                 continue
             obj = self.save_object(form)
             if form.cleaned_data.get("DELETE", False):
@@ -715,6 +722,11 @@ class BaseDocumentFormSet(BaseFormSet):
                     # if it has no delete method it is an embedded object. We
                     # just don't add to the list and it's gone. Cool huh?
                     continue
+                self.deleted_objects.append(obj)
+            elif new:
+                self.new_objects.append(obj)
+            elif changed:
+                self.changed_objects.append(obj)
             if commit:
                 obj.save()
             saved.append(obj)```

replabrobin avatar Feb 02 '16 16:02 replabrobin