Bugfix: Reload version attr in OCC

remotes/origin/enhancement/email-actions
Anler Hp 2014-06-26 09:59:44 +02:00
parent 077de2bf4e
commit e2b8687980
2 changed files with 16 additions and 0 deletions

View File

@ -27,3 +27,13 @@ def get_typename_for_model_class(model:object, for_concrete_model=True) -> str:
model = model._meta.proxy_for_model model = model._meta.proxy_for_model
return "{0}.{1}".format(model._meta.app_label, model._meta.model_name) return "{0}.{1}".format(model._meta.app_label, model._meta.model_name)
def reload_attribute(model_instance, attr_name):
"""Fetch the stored value of a model instance attribute.
:param model_instance: Model instance.
:param attr_name: Attribute name to fetch.
"""
qs = type(model_instance).objects.filter(id=model_instance.id)
return qs.values_list(attr_name, flat=True)[0]

View File

@ -18,6 +18,7 @@ from django.db import models
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from taiga.base import exceptions as exc from taiga.base import exceptions as exc
from taiga.base.utils import db
class OCCResourceMixin(object): class OCCResourceMixin(object):
@ -37,6 +38,11 @@ class OCCResourceMixin(object):
super().pre_save(obj) super().pre_save(obj)
def post_save(self, obj, created=False):
super().post_save(obj, created)
if not created:
obj.version = db.reload_attribute(obj, 'version')
class OCCModelMixin(models.Model): class OCCModelMixin(models.Model):
""" """