fix several minor bugs with data types
This commit is contained in:
parent
275724cc8e
commit
e65a90d9bd
2 changed files with 4 additions and 11 deletions
|
@ -4,6 +4,7 @@ from collections import OrderedDict
|
||||||
|
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.core.serializers.json import DjangoJSONEncoder
|
||||||
from django.db import models, transaction
|
from django.db import models, transaction
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.db.models.fields.related_descriptors import ForwardManyToOneDescriptor, ManyToManyDescriptor
|
from django.db.models.fields.related_descriptors import ForwardManyToOneDescriptor, ManyToManyDescriptor
|
||||||
|
@ -42,7 +43,6 @@ class ChangeSet(models.Model):
|
||||||
self.m2m_removed = {}
|
self.m2m_removed = {}
|
||||||
self._last_change_pk = 0
|
self._last_change_pk = 0
|
||||||
|
|
||||||
@property
|
|
||||||
def relevant_changes(self):
|
def relevant_changes(self):
|
||||||
return self.changes.filter(discarded_by__isnull=True).exclude(action='restore')
|
return self.changes.filter(discarded_by__isnull=True).exclude(action='restore')
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ class ChangeSet(models.Model):
|
||||||
if get_history:
|
if get_history:
|
||||||
self.changes_qs = self.changes.all()
|
self.changes_qs = self.changes.all()
|
||||||
else:
|
else:
|
||||||
self.changes_qs = self.relevant_changes
|
self.changes_qs = self.relevant_changes()
|
||||||
|
|
||||||
for change in self.changes_qs:
|
for change in self.changes_qs:
|
||||||
self._parse_change(change)
|
self._parse_change(change)
|
||||||
|
@ -300,8 +300,8 @@ class ChangeSet(models.Model):
|
||||||
obj.pk = 'c%d' % change.pk
|
obj.pk = 'c%d' % change.pk
|
||||||
|
|
||||||
def _add_value(self, action, obj, name, value, author=None):
|
def _add_value(self, action, obj, name, value, author=None):
|
||||||
return self._new_change(author=author, action=action, obj=obj,
|
return self._new_change(author=author, action=action, obj=obj, field_name=name,
|
||||||
field_name=name, field_value=json.dumps(value, ensure_ascii=False))
|
field_value=json.dumps(value, ensure_ascii=False, cls=DjangoJSONEncoder))
|
||||||
|
|
||||||
def add_update(self, obj, name, value, author=None):
|
def add_update(self, obj, name, value, author=None):
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
|
@ -408,7 +408,6 @@ class Change(models.Model):
|
||||||
return 'c' + str(self.pk)
|
return 'c' + str(self.pk)
|
||||||
raise TypeError('existing_model_pk or created_object have to be set.')
|
raise TypeError('existing_model_pk or created_object have to be set.')
|
||||||
|
|
||||||
@property
|
|
||||||
def other_changes(self):
|
def other_changes(self):
|
||||||
"""
|
"""
|
||||||
get queryset of other active changes on the same object
|
get queryset of other active changes on the same object
|
||||||
|
|
|
@ -371,12 +371,6 @@ class BaseQueryWrapper(BaseWrapper):
|
||||||
(add_pks if check(new_value) else remove_pks).append(pk)
|
(add_pks if check(new_value) else remove_pks).append(pk)
|
||||||
created_pks = set()
|
created_pks = set()
|
||||||
for pk, values in chain(*(self._changeset.created_objects.get(model, {}).items() for model in models)):
|
for pk, values in chain(*(self._changeset.created_objects.get(model, {}).items() for model in models)):
|
||||||
try:
|
|
||||||
if check(values[field_name]):
|
|
||||||
created_pks.add(pk)
|
|
||||||
continue
|
|
||||||
except AttributeError:
|
|
||||||
pass
|
|
||||||
if check(getattr(self._changeset.get_created_object(self._obj.model, pk), field_name)):
|
if check(getattr(self._changeset.get_created_object(self._obj.model, pk), field_name)):
|
||||||
created_pks.add(pk)
|
created_pks.add(pk)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue