fix error when creating new objects

This commit is contained in:
Laura Klünder 2017-06-25 11:40:22 +02:00
parent aadb81c237
commit 7a2854317e

View file

@ -381,7 +381,10 @@ class ChangeSet(models.Model):
model = type(obj)
field = model._meta.get_field('titles' if name.startswith('title_') else name)
with transaction.atomic():
current_obj = model.objects.only(field.name).get(pk=obj.pk)
if is_created_pk(obj.pk):
current_obj = model()
else:
current_obj = model.objects.only(field.name).get(pk=obj.pk)
try:
current_value = getattr(current_obj, field.attname)
except AttributeError: