fix model transfer
This commit is contained in:
parent
a8368e92b8
commit
b2e11527cb
|
@ -8,6 +8,7 @@ from teal.db import CASCADE_OWN
|
||||||
|
|
||||||
from ereuse_devicehub.db import db
|
from ereuse_devicehub.db import db
|
||||||
from ereuse_devicehub.resources.models import Thing
|
from ereuse_devicehub.resources.models import Thing
|
||||||
|
from ereuse_devicehub.resources.user.models import User
|
||||||
|
|
||||||
|
|
||||||
class Transfer(Thing):
|
class Transfer(Thing):
|
||||||
|
@ -18,7 +19,7 @@ class Transfer(Thing):
|
||||||
|
|
||||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid4)
|
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid4)
|
||||||
code = Column(CIText(), default='', nullable=False)
|
code = Column(CIText(), default='', nullable=False)
|
||||||
closed = Boolean(default=False)
|
closed = Column(Boolean, nullable=False, default=False)
|
||||||
date = Column(db.TIMESTAMP(timezone=True))
|
date = Column(db.TIMESTAMP(timezone=True))
|
||||||
description = Column(CIText(), default='', nullable=True)
|
description = Column(CIText(), default='', nullable=True)
|
||||||
lot_id = db.Column(
|
lot_id = db.Column(
|
||||||
|
@ -31,3 +32,7 @@ class Transfer(Thing):
|
||||||
backref=backref('transfer', lazy=True, uselist=False, cascade=CASCADE_OWN),
|
backref=backref('transfer', lazy=True, uselist=False, cascade=CASCADE_OWN),
|
||||||
primaryjoin='Transfer.lot_id == Lot.id',
|
primaryjoin='Transfer.lot_id == Lot.id',
|
||||||
)
|
)
|
||||||
|
user_from_id = db.Column(UUID(as_uuid=True), db.ForeignKey(User.id), nullable=True)
|
||||||
|
user_from = db.relationship(User, primaryjoin=user_from_id == User.id)
|
||||||
|
user_to_id = db.Column(UUID(as_uuid=True), db.ForeignKey(User.id), nullable=True)
|
||||||
|
user_to = db.relationship(User, primaryjoin=user_to_id == User.id)
|
||||||
|
|
|
@ -50,8 +50,12 @@ def upgrade():
|
||||||
comment='A comment about the action.',
|
comment='A comment about the action.',
|
||||||
),
|
),
|
||||||
sa.Column('date', sa.TIMESTAMP(timezone=True), nullable=True),
|
sa.Column('date', sa.TIMESTAMP(timezone=True), nullable=True),
|
||||||
sa.Column('lot_id', postgresql.UUID(as_uuid=True), nullable=True),
|
sa.Column('lot_id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||||
|
sa.Column('user_to_id', postgresql.UUID(as_uuid=True), nullable=True),
|
||||||
|
sa.Column('user_from_id', postgresql.UUID(as_uuid=True), nullable=True),
|
||||||
sa.ForeignKeyConstraint(['lot_id'], [f'{get_inv()}.lot.id']),
|
sa.ForeignKeyConstraint(['lot_id'], [f'{get_inv()}.lot.id']),
|
||||||
|
sa.ForeignKeyConstraint(['user_from_id'], ['common.user.id']),
|
||||||
|
sa.ForeignKeyConstraint(['user_to_id'], ['common.user.id']),
|
||||||
sa.PrimaryKeyConstraint('id'),
|
sa.PrimaryKeyConstraint('id'),
|
||||||
schema=f'{get_inv()}',
|
schema=f'{get_inv()}',
|
||||||
)
|
)
|
||||||
|
|
Reference in New Issue