updated constraint and added devices fk's

This commit is contained in:
Thomas Nahuel Rusiecki 2025-02-24 18:23:37 -03:00
parent 0d256787e9
commit 9c1aa20887

View file

@ -39,7 +39,7 @@ class Lot(models.Model):
class Meta: class Meta:
constraints = [ 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): def remove(self, v):
for d in DeviceLot.objects.filter(lot=self, device_id=v): for d in DeviceLot.objects.filter(lot=self, device_id=v):
d.delete() d.delete()
@property
def devices(self):
return DeviceLot.objects.filter(lot=self)
class LotProperty(Property): class LotProperty(Property):
lot = models.ForeignKey(Lot, on_delete=models.CASCADE) lot = models.ForeignKey(Lot, on_delete=models.CASCADE)