diff --git a/models.py b/models.py index 243f674..d367d66 100644 --- a/models.py +++ b/models.py @@ -83,11 +83,6 @@ class EavAttribute(models.Model): self.slug = EavSlugField.create_slug_from_name(self.name) self.full_clean() super(EavAttribute, self).save(*args, **kwargs) - EavEntity.update_all_caches() - - def delete(self, *args, **kwargs): - EavEntity.update_all_caches() - super(EavAttribute, self).delete(*args, **kwargs) def add_label(self, label): label, created = EavAttributeLabel.objects.get_or_create(name=label) @@ -259,15 +254,7 @@ class EavEntity(object): cache['attributes'] = cls.get_eav_attributes().select_related() cache['slug_mapping'] = dict((s.slug, s) for s in cache['attributes']) return cache - - @classmethod - def update_all_caches(cls): - """ - Update all caches of registered entities. - """ - from .utils import EavRegistry - for entity in EavRegistry.cache.itervalues(): - cls.update_attr_cache_for_model(entity['model_cls']) + @classmethod def flush_attr_cache_for_model(cls, model_cls): diff --git a/utils.py b/utils.py index 8c94d27..b39dab3 100644 --- a/utils.py +++ b/utils.py @@ -1,4 +1,5 @@ from django.contrib.contenttypes import generic +from django.db.utils import DatabaseError from django.db.models.signals import post_init, post_save, post_delete from .managers import EntityManager from .models import (EavEntity, EavAttribute, EavValue, @@ -86,7 +87,11 @@ class EavRegistry(object): mgr = EntityManager() mgr.contribute_to_class(model_cls, config_cls.manager_field_name) - EavEntity.update_attr_cache_for_model(model_cls) + + try: + EavEntity.update_attr_cache_for_model(model_cls) + except DatabaseError: + pass gr_name = config_cls.generic_relation_field_name generic_relation = generic.GenericRelation(EavValue,