change device for placeholders in lots

This commit is contained in:
Cayo Puigdefabregas 2022-07-15 18:07:39 +02:00
parent 74260c6a00
commit 9e42ccafc0
2 changed files with 11 additions and 3 deletions

View File

@ -7,6 +7,7 @@ from citext import CIText
from flask import g
from sqlalchemy import TEXT
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import relationship
from sqlalchemy_utils import LtreeType
from sqlalchemy_utils.types.ltree import LQUERY
from teal.db import CASCADE_OWN, IntEnum, UUIDLtree, check_range
@ -243,6 +244,10 @@ class LotDevice(db.Model):
)
author = db.relationship(User, primaryjoin=author_id == User.id)
author_id.comment = """The user that put the device in the lot."""
device = relationship(
'Device',
primaryjoin='Device.id == LotDevice.device_id',
)
class Path(db.Model):

View File

@ -18,6 +18,7 @@ from ereuse_devicehub.resources.action.models import (
Use,
)
from ereuse_devicehub.resources.device.models import Computer, Placeholder
from ereuse_devicehub.resources.lot.models import LotDevice
app = Devicehub(inventory=DevicehubConfig.DB_SCHEMA)
app.app_context().push()
@ -63,9 +64,11 @@ def clone_device(device):
lots = [x for x in device.lots]
for lot in lots:
set_devices = lot.devices - {device}
set_devices.add(new_device)
lot.devices.update(set_devices)
for rel_lot in LotDevice.query.filter_by(lot_id=lot.id, device=device):
rel_lot.device = new_device
# set_devices = lot.devices - {device}
# set_devices.add(new_device)
# lot.devices.update(set_devices)
return new_device