summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Server/models.py
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander.sulfrian@fu-berlin.de>2015-09-23 18:26:04 +0200
committerAlexander Sulfrian <alexander.sulfrian@fu-berlin.de>2015-09-23 19:44:16 +0200
commit98e7d57e54ea8122b705e643cce23ccc9aa7cd86 (patch)
tree4df34c0228ac1c2f499665d2b8181df1a5fdac37 /src/lib/Bcfg2/Server/models.py
parent24edb2b192ee3c880722e800a001e38807f398b6 (diff)
downloadbcfg2-98e7d57e54ea8122b705e643cce23ccc9aa7cd86.tar.gz
bcfg2-98e7d57e54ea8122b705e643cce23ccc9aa7cd86.tar.bz2
bcfg2-98e7d57e54ea8122b705e643cce23ccc9aa7cd86.zip
Reports: Fix InternalDatabaseVersion
You could not import a class, that is defined in a function. We need to return the class, but we do not want to define it multiple times. So we have to save the class in a global variable.
Diffstat (limited to 'src/lib/Bcfg2/Server/models.py')
-rw-r--r--src/lib/Bcfg2/Server/models.py29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/lib/Bcfg2/Server/models.py b/src/lib/Bcfg2/Server/models.py
index 8d6642a25..9c0153c74 100644
--- a/src/lib/Bcfg2/Server/models.py
+++ b/src/lib/Bcfg2/Server/models.py
@@ -8,6 +8,7 @@ import Bcfg2.Server.Plugins
LOGGER = logging.getLogger(__name__)
MODELS = []
+INTERNAL_DATABASE_VERSION = None
class _OptionContainer(object):
@@ -56,15 +57,23 @@ def load_models(plugins=None):
setattr(sys.modules[__name__], sym, obj)
MODELS.append(sym)
- class InternalDatabaseVersion(models.Model):
- """ Object that tell us to which version the database is """
- version = models.IntegerField()
- updated = models.DateTimeField(auto_now_add=True)
+def internal_database_version():
+ global INTERNAL_DATABASE_VERSION
- def __str__(self):
- return "version %d updated %s" % (self.version,
- self.updated.isoformat())
+ if INTERNAL_DATABASE_VERSION is None:
+ from django.db import models
+ class InternalDatabaseVersion(models.Model):
+ """ Object that tell us to which version the database is """
+ version = models.IntegerField()
+ updated = models.DateTimeField(auto_now_add=True)
- class Meta: # pylint: disable=C0111,W0232
- app_label = "reports"
- get_latest_by = "version"
+ def __str__(self):
+ return "version %d updated %s" % (self.version,
+ self.updated.isoformat())
+
+ class Meta: # pylint: disable=C0111,W0232
+ app_label = "reports"
+ get_latest_by = "version"
+ INTERNAL_DATABASE_VERSION = InternalDatabaseVersion
+
+ return INTERNAL_DATABASE_VERSION.objects