cleaner get/create impl

This commit is contained in:
Wayne Witzel III 2016-03-31 09:58:23 -04:00
parent e84008fe51
commit a1d1ddee2b

View File

@ -136,11 +136,8 @@ class Role(CommonModelNameNotUnique):
@staticmethod
def singleton(name):
try:
return Role.objects.get(singleton_name=name)
except Role.DoesNotExist:
ret = Role.objects.create(singleton_name=name, name=name)
return ret
role, _ = Role.objects.get_or_create(singleton_name=name, name=name)
return role
def is_ancestor_of(self, role):
return role.ancestors.filter(id=self.id).exists()