diff --git a/.gitignore b/.gitignore
index dde0baf..a695b50 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,6 +8,9 @@ sdist/
*.egg-info/
.DS_Store
+# Editor settings
+.vscode/
+
# Unit test / coverage reports
htmlcov/
.tox/
diff --git a/README.md b/README.md
index 53cc8fa..39d898c 100644
--- a/README.md
+++ b/README.md
@@ -157,7 +157,6 @@ Running tests:
```
make test
-tox
```
Testing new changes on test project:
@@ -171,12 +170,11 @@ make run
Honestly this part is just for my reference. But who knows :) maybe we'll have another maintainer in the future.
-Run tests, check coverage, check readme, run tox
+Run tests, check coverage, check readme
```
make test
make check-readme
-tox
```
Update version in `setup.py`
diff --git a/admin_confirm/admin.py b/admin_confirm/admin.py
index 6198712..1249a45 100644
--- a/admin_confirm/admin.py
+++ b/admin_confirm/admin.py
@@ -6,7 +6,8 @@ from django.template.response import TemplateResponse
from django.contrib.admin.options import TO_FIELD_VAR
from django.utils.translation import gettext as _
from django.contrib.admin import helpers
-from django.db.models import Model
+from django.db.models import Model, ManyToManyField
+
from django.forms import ModelForm
from admin_confirm.utils import snake_to_title_case
@@ -119,18 +120,43 @@ class AdminConfirmMixin:
default_value = model._meta.get_field(name).get_default()
if new_value is not None and new_value != default_value:
# Show what the default value is
- changed_data[name] = [str(default_value), new_value]
+ changed_data[name] = [default_value, new_value]
else:
# Parse the changed data - Note that using form.changed_data would not work because initial is not set
for name, new_value in form.cleaned_data.items():
# Since the form considers initial as the value first shown in the form
# It could be incorrect when user hits save, and then hits "No, go back to edit"
obj.refresh_from_db()
+ # Note: getattr does not work on ManyToManyFields
+ field_object = model._meta.get_field(name)
initial_value = getattr(obj, name)
+ if isinstance(field_object, ManyToManyField):
+ initial_value = field_object.value_to_string(obj)
+
if initial_value != new_value:
changed_data[name] = [initial_value, new_value]
+
+ print(changed_data)
return changed_data
+ def _get_form_data(self, request):
+ """
+ Parses the request post params into a format that can be used for the hidden form on the
+ change confirmation page.
+ """
+ form_data = request.POST.copy()
+
+ for key in SAVE_ACTIONS + [
+ "_confirm_change",
+ "_confirm_add",
+ "csrfmiddlewaretoken",
+ ]:
+ if form_data.get(key):
+ form_data.pop(key)
+
+ form_data = [(k, list(v)) for k, v in form_data.lists()]
+ return form_data
+
def _change_confirmation_view(self, request, object_id, form_url, extra_context):
# This code is taken from super()._changeform_view
to_field = request.POST.get(TO_FIELD_VAR, request.GET.get(TO_FIELD_VAR))
@@ -174,18 +200,14 @@ class AdminConfirmMixin:
return super()._changeform_view(request, object_id, form_url, extra_context)
# Parse raw form data from POST
- form_data = {}
+ form_data = self._get_form_data(request)
# Parse the original save action from request
save_action = None
- for key, value in request.POST.items():
+ for key in request.POST.keys():
if key in SAVE_ACTIONS:
save_action = key
- continue
+ break
- if key.startswith("_") or key == "csrfmiddlewaretoken":
- continue
-
- form_data[key] = value
title_action = _("adding") if add else _("changing")
diff --git a/admin_confirm/templates/admin/change_confirmation.html b/admin_confirm/templates/admin/change_confirmation.html
index 99b3e25..dc2adee 100644
--- a/admin_confirm/templates/admin/change_confirmation.html
+++ b/admin_confirm/templates/admin/change_confirmation.html
@@ -43,8 +43,10 @@