Implement CRUD for asset groups

This commit is contained in:
2023-02-10 07:20:19 +00:00
parent e00cdc906e
commit 72055181bc
7 changed files with 237 additions and 0 deletions

View File

@@ -399,3 +399,38 @@ class RiskModel(models.Model):
def __str__(self):
return self.name
class AssetGroup(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
name = models.CharField(max_length=255)
description = models.TextField(null=True, blank=True)
# Account for checking pairs on children if specified
account = models.ForeignKey(Account, on_delete=models.CASCADE)
# Dict like {"RUB": True, "USD": False}
allowed = models.JSONField(null=True, blank=True, default={})
def __str__(self):
return self.name
@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)}"
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)
group = models.ForeignKey(
AssetGroup, on_delete=models.CASCADE, null=True, blank=True
)