Add asset groups and restrictions

This commit is contained in:
2023-02-10 14:33:17 +00:00
parent 7938bffc8d
commit f81d632df3
7 changed files with 230 additions and 32 deletions

View File

@@ -410,7 +410,7 @@ class AssetGroup(models.Model):
account = models.ForeignKey(Account, on_delete=models.CASCADE)
# Dict like {"RUB": True, "USD": False}
allowed = models.JSONField(null=True, blank=True, default={})
allowed = models.JSONField(null=True, blank=True, default=dict)
def __str__(self):
return self.name
@@ -424,12 +424,20 @@ class AssetGroup(models.Model):
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):
user = models.ForeignKey(User, on_delete=models.CASCADE)
name = models.CharField(max_length=255)
description = models.TextField(null=True, blank=True)
pairs = models.CharField(max_length=4096, null=True, blank=True)
pairs_parsed = models.JSONField(null=True, blank=True)
group = models.ForeignKey(
AssetGroup, on_delete=models.CASCADE, null=True, blank=True