diff options
| -rw-r--r-- | ishtar_common/serializers.py | 5 | ||||
| -rw-r--r-- | ishtar_common/serializers_utils.py | 11 | 
2 files changed, 13 insertions, 3 deletions
diff --git a/ishtar_common/serializers.py b/ishtar_common/serializers.py index 17b4f9457..50a48d79b 100644 --- a/ishtar_common/serializers.py +++ b/ishtar_common/serializers.py @@ -9,6 +9,7 @@ from django.apps import apps  from django.conf import settings  from django.core.serializers import deserialize +from django.contrib.contenttypes.models import ContentType  from django.contrib.auth.models import Group, Permission  from . import models @@ -36,7 +37,7 @@ TYPE_MODEL_EXCLUDE = ["Area", "OperationTypeOld", "ProfileTypeSummary"]  def get_type_models(): -    return [Permission, Group] + [ +    return [ContentType, Permission, Group] + [          model for model in apps.get_models()          if isinstance(model(), models.GeneralType) and (                  model.__name__ not in TYPE_MODEL_EXCLUDE) @@ -328,7 +329,7 @@ def restore_serialized(archive_name, user=None, delete_existing=False,                      if len(path) != 2 or path[0] != current_dir:                          continue                      model = get_model_from_filename(path[-1]) -                    if current_model and current_model != model: +                    if not model or (current_model and current_model != model):                          continue                      if delete_existing:                          model.objects.all().delete() diff --git a/ishtar_common/serializers_utils.py b/ishtar_common/serializers_utils.py index 2242c349e..efa390e59 100644 --- a/ishtar_common/serializers_utils.py +++ b/ishtar_common/serializers_utils.py @@ -20,7 +20,16 @@ SERIALIZATION_VERSION = "1.0"  def get_model_from_filename(filename):      filename = filename.split(".")[0]  # remove extension      module_name, model_name = filename.split("__") -    module = importlib.import_module(module_name + ".models") +    if module_name == "django": +        if model_name in ("Group", "Permission"): +            module = importlib.import_module("django.contrib.auth.models") +        elif model_name in ("ContentType", ): +            module = importlib.import_module( +                "django.contrib.contenttypes.models") +        else: +            return +    else: +        module = importlib.import_module(module_name + ".models")      return getattr(module, model_name)  | 
