change device for placeholders in lots
This commit is contained in:
parent
74260c6a00
commit
9e42ccafc0
|
@ -7,6 +7,7 @@ from citext import CIText
|
||||||
from flask import g
|
from flask import g
|
||||||
from sqlalchemy import TEXT
|
from sqlalchemy import TEXT
|
||||||
from sqlalchemy.dialects.postgresql import UUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
|
from sqlalchemy.orm import relationship
|
||||||
from sqlalchemy_utils import LtreeType
|
from sqlalchemy_utils import LtreeType
|
||||||
from sqlalchemy_utils.types.ltree import LQUERY
|
from sqlalchemy_utils.types.ltree import LQUERY
|
||||||
from teal.db import CASCADE_OWN, IntEnum, UUIDLtree, check_range
|
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 = db.relationship(User, primaryjoin=author_id == User.id)
|
||||||
author_id.comment = """The user that put the device in the lot."""
|
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):
|
class Path(db.Model):
|
||||||
|
|
|
@ -18,6 +18,7 @@ from ereuse_devicehub.resources.action.models import (
|
||||||
Use,
|
Use,
|
||||||
)
|
)
|
||||||
from ereuse_devicehub.resources.device.models import Computer, Placeholder
|
from ereuse_devicehub.resources.device.models import Computer, Placeholder
|
||||||
|
from ereuse_devicehub.resources.lot.models import LotDevice
|
||||||
|
|
||||||
app = Devicehub(inventory=DevicehubConfig.DB_SCHEMA)
|
app = Devicehub(inventory=DevicehubConfig.DB_SCHEMA)
|
||||||
app.app_context().push()
|
app.app_context().push()
|
||||||
|
@ -63,9 +64,11 @@ def clone_device(device):
|
||||||
|
|
||||||
lots = [x for x in device.lots]
|
lots = [x for x in device.lots]
|
||||||
for lot in lots:
|
for lot in lots:
|
||||||
set_devices = lot.devices - {device}
|
for rel_lot in LotDevice.query.filter_by(lot_id=lot.id, device=device):
|
||||||
set_devices.add(new_device)
|
rel_lot.device = new_device
|
||||||
lot.devices.update(set_devices)
|
# set_devices = lot.devices - {device}
|
||||||
|
# set_devices.add(new_device)
|
||||||
|
# lot.devices.update(set_devices)
|
||||||
return new_device
|
return new_device
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue