From 5ce6a478aa53ce1d24d53abfa61944b22ac9b674 Mon Sep 17 00:00:00 2001
From: Andre Anjos <andre.anjos@idiap.ch>
Date: Mon, 4 Jul 2016 17:15:35 +0200
Subject: [PATCH] [utils] Sub-select apps which are installed before restoring

---
 beat/web/utils/management/commands/restore.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/beat/web/utils/management/commands/restore.py b/beat/web/utils/management/commands/restore.py
index bd710aea0..e7b769523 100644
--- a/beat/web/utils/management/commands/restore.py
+++ b/beat/web/utils/management/commands/restore.py
@@ -37,7 +37,7 @@ import tempfile
 from django.core.management import call_command
 from django.core.management.base import BaseCommand, CommandError
 from django.conf import settings
-from django.apps import apps
+from django.apps import apps, registry
 
 from .backup import APPS
 
@@ -102,6 +102,11 @@ class Command(BaseCommand):
 
             exclude = arguments.get('exclude')
 
+            # remove uninstalled apps
+            global APPS
+            installed_apps = registry.apps.all_models.keys()
+            exclude += [app for app in APPS if app not in installed_apps]
+
             arguments = dict(
                     verbosity=arguments.get('verbosity'),
                     interactive=False,
-- 
GitLab