mirror of
https://github.com/jazzband/django-auditlog.git
synced 2026-03-16 22:20:26 +00:00
Make M2M changes comply with JSONField properly (#514)
This commit is contained in:
parent
fcb6c4ce27
commit
98fe8d4173
2 changed files with 22 additions and 8 deletions
|
|
@ -126,15 +126,14 @@ class LogEntryManager(models.Manager):
|
|||
kwargs.setdefault("additional_data", get_additional_data())
|
||||
|
||||
objects = [smart_str(instance) for instance in changed_queryset]
|
||||
kwargs["changes"] = json.dumps(
|
||||
{
|
||||
field_name: {
|
||||
"type": "m2m",
|
||||
"operation": operation,
|
||||
"objects": objects,
|
||||
}
|
||||
kwargs["changes"] = {
|
||||
field_name: {
|
||||
"type": "m2m",
|
||||
"operation": operation,
|
||||
"objects": objects,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
kwargs.setdefault("cid", get_cid())
|
||||
return self.create(**kwargs)
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ from django.test import RequestFactory, TestCase, override_settings
|
|||
from django.urls import reverse
|
||||
from django.utils import dateformat, formats
|
||||
from django.utils import timezone as django_timezone
|
||||
from django.utils.encoding import smart_str
|
||||
|
||||
from auditlog.admin import LogEntryAdmin
|
||||
from auditlog.cid import get_cid
|
||||
|
|
@ -400,6 +401,20 @@ class ManyRelatedModelTest(TestCase):
|
|||
log_entry.additional_data, {"related_model_id": self.related.id}
|
||||
)
|
||||
|
||||
def test_changes(self):
|
||||
self.obj.related.add(self.related)
|
||||
log_entry = self.obj.history.first()
|
||||
self.assertEqual(
|
||||
log_entry.changes,
|
||||
{
|
||||
"related": {
|
||||
"type": "m2m",
|
||||
"operation": "add",
|
||||
"objects": [smart_str(self.related)],
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
class MiddlewareTest(TestCase):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue