Adding an instance manager.

This commit is contained in:
Luke Sneeringer
2014-09-30 10:38:37 -05:00
parent f77ae6f1bc
commit a9260db790
2 changed files with 31 additions and 1 deletions
+27
View File
@@ -0,0 +1,27 @@
# Copyright (c) 2014 Ansible, Inc.
# All Rights Reserved.
from django.conf import settings
from django.db import models
from django.utils.functional import cached_property
class InstanceManager(models.Manager):
"""A custom manager class for the Instance model.
Provides "table-level" methods including getting the currently active
instance or role.
"""
@cached_property
def me(self):
"""Return the currently active instance."""
return self.get(uuid=settings.SYSTEM_UUID)
@cached_property
def my_role(self):
"""Return the role of the currently active instance, as a string
('primary' or 'secondary').
"""
if self.me.primary:
return 'primary'
return 'secondary'