From 41926ea85ad7c246b73b6d99001757f7df75ad5c Mon Sep 17 00:00:00 2001 From: thomas rusiecki Date: Tue, 12 Nov 2024 12:22:09 -0300 Subject: [PATCH] split into system and user properties --- evidence/models.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/evidence/models.py b/evidence/models.py index e9af092..41a1665 100644 --- a/evidence/models.py +++ b/evidence/models.py @@ -3,13 +3,15 @@ import json from dmidecode import DMIParse from django.db import models + +from django.db.models import Q from utils.constants import STR_EXTEND_SIZE, CHASSIS_DH from evidence.xapian import search from evidence.parse_details import ParseSnapshot from user.models import User, Institution - -class Annotation(models.Model): +#TODO: base class is abstract; revise if should be for query efficiency +class Property(models.Model): class Type(models.IntegerChoices): SYSTEM = 0, "System" USER = 1, "User" @@ -30,6 +32,30 @@ class Annotation(models.Model): models.UniqueConstraint( fields=["type", "key", "uuid"], name="unique_type_key_uuid") ] + abstract = True + +class SystemProperty(Property): + + class Meta: + constraints = [ + models.CheckConstraint( + check=~Q(type=1), #Enforce that type is not User + name='property_cannot_be_user' + ), + ] + +class UserProperty(Property): + + type = models.SmallIntegerField(default=Property.Type.USER) + + class Meta: + constraints = [ + models.CheckConstraint( + check=Q(type=1), #Enforce that type is User + name='property_needs_to_be_user' + ), + ] + class Evidence: