Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion simple_history/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
from django.db import transaction
from django.db.models import Case, ForeignKey, ManyToManyField, Q, When
from django.db.models import (
Case,
ForeignKey,
JSONField,
ManyToManyField,
Q,
Value,
When,
)
from django.forms.models import model_to_dict

from simple_history.exceptions import AlternativeManagerError, NotHistoricalModelError
Expand All @@ -18,6 +26,11 @@
if field.primary_key is True:
if value is not None:
attrs[field.attname] = value
elif isinstance(field, JSONField):
if value is None and field.null is True:
attrs[f"{field.attname}__isnull"] = True

Check warning on line 31 in simple_history/utils.py

View check run for this annotation

Codecov / codecov/patch

simple_history/utils.py#L31

Added line #L31 was not covered by tests
else:
attrs[field.attname] = Value(value, JSONField())

Check warning on line 33 in simple_history/utils.py

View check run for this annotation

Codecov / codecov/patch

simple_history/utils.py#L33

Added line #L33 was not covered by tests
else:
attrs[field.attname] = value

Expand Down