Re-add property fields

This commit is contained in:
2023-02-11 18:07:05 +00:00
parent 7afdd39af7
commit bdf8f04210
3 changed files with 25 additions and 2 deletions

View File

@@ -418,7 +418,23 @@ class AssetGroup(models.Model):
allowed = models.JSONField(null=True, blank=True, default=dict)
def __str__(self):
return f"{self.name}"
return f"{self.name} ({self.restrictions})"
@property
def matches(self):
"""
Get the total number of matches for this group.
"""
if isinstance(self.allowed, dict):
truthy_values = [x for x in self.allowed.values() if x is True]
return f"{len(truthy_values)}/{len(self.allowed)}"
@property
def restrictions(self):
"""
Get the total number of restrictions for this group.
"""
return self.assetrestriction_set.count()
class AssetRestriction(models.Model):