diff --git a/ereuse_devicehub/resources/lot/models.py b/ereuse_devicehub/resources/lot/models.py index c2309224..461e7c69 100644 --- a/ereuse_devicehub/resources/lot/models.py +++ b/ereuse_devicehub/resources/lot/models.py @@ -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): diff --git a/scripts/create_placeholders.py b/scripts/create_placeholders.py index 30a4aad9..7a7f2773 100644 --- a/scripts/create_placeholders.py +++ b/scripts/create_placeholders.py @@ -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