From 9c1aa20887a12821cb77630ca257e9fbb5ee68ed Mon Sep 17 00:00:00 2001 From: Thomas Rusiecki Date: Mon, 24 Feb 2025 18:23:37 -0300 Subject: [PATCH] updated constraint and added devices fk's --- lot/models.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lot/models.py b/lot/models.py index 90c1502..d651689 100644 --- a/lot/models.py +++ b/lot/models.py @@ -39,7 +39,7 @@ class Lot(models.Model): class Meta: constraints = [ - models.UniqueConstraint(fields=['owner', 'name'], name='unique_institution_and_name') + models.UniqueConstraint(fields=['owner', 'name', 'type'], name='unique_institution_and_name') ] @@ -51,6 +51,10 @@ class Lot(models.Model): def remove(self, v): for d in DeviceLot.objects.filter(lot=self, device_id=v): d.delete() + @property + def devices(self): + return DeviceLot.objects.filter(lot=self) + class LotProperty(Property): lot = models.ForeignKey(Lot, on_delete=models.CASCADE)