fixing models

This commit is contained in:
Cayo Puigdefabregas 2021-03-16 21:39:17 +01:00
parent d7e50be052
commit 34aeae9908
3 changed files with 5 additions and 28 deletions

View File

@ -26,32 +26,13 @@ def get_inv():
return INV
def upgrade():
user_from_id = db.Column(UUID(as_uuid=True),
db.ForeignKey(User.id),
nullable=False,
default=lambda: g.user.id)
user_from = db.relationship(User, primaryjoin=user_from_id == User.id)
user_from_comment = """The user that offers the device due this deal."""
user_to_id = db.Column(UUID(as_uuid=True),
db.ForeignKey(User.id),
nullable=False,
default=lambda: g.user.id)
user_to = db.relationship(User, primaryjoin=user_to_id == User.id)
user_to_comment = """The user that gets the device due this deal."""
price = Column(Float(decimal_return_scale=2), nullable=True)
date = Column(db.TIMESTAMP(timezone=True))
user_to_string = Column(CIText())
user_from_string = Column(CIText())
++++
op.drop_table('trade', schema=f'{get_inv()}')
op.create_table('trade',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('date', sa.TIMESTAMP(timezone=True), nullable=True),
sa.Column('user_from_id', postgresql.UUID(as_uuid=True), nullable=True),
sa.Column('user_to_id', postgresql.UUID(as_uuid=True), nullable=True),
sa.Column('user_from_string', citext.CIText(), nullable=True),
sa.Column('user_to_string', citext.CIText(), nullable=True),
sa.Column('price', sa.Float(decimal_return_scale=4), nullable=True),
sa.Column('user_from_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('user_to_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.ForeignKeyConstraint(['id'], [f'{get_inv()}.action.id'], ),
sa.ForeignKeyConstraint(['from_id'], [f'common.user.id'], ),
@ -62,4 +43,4 @@ def upgrade():
def downgrade():
pass
op.drop_table('trade', schema=f'{get_inv()}')

View File

@ -1452,16 +1452,12 @@ class Trade(JoinedTableMixin, ActionWithMultipleDevices):
default=lambda: g.user.id)
user_from = db.relationship(User, primaryjoin=user_from_id == User.id)
user_from_comment = """The user that offers the device due this deal."""
user_from_string = Column(CIText())
user_from_string_comment = """The user outsite of devicehub that offers the device."""
user_to_id = db.Column(UUID(as_uuid=True),
db.ForeignKey(User.id),
nullable=False,
default=lambda: g.user.id)
user_to = db.relationship(User, primaryjoin=user_to_id == User.id)
user_to_comment = """The user that gets the device due this deal."""
user_to_string = Column(CIText())
user_to_string_comment = """The user outsite of devicehub that offers the device."""
price = Column(Float(decimal_return_scale=2), nullable=True)
date = Column(db.TIMESTAMP(timezone=True))

View File

@ -460,7 +460,7 @@ class Trade(ActionWithMultipleDevices):
shipping_date = DateTime(data_key='shippingDate')
invoice_number = SanitizedStr(validate=Length(max=STR_SIZE), data_key='invoiceNumber')
price = NestedOn(Price)
to = NestedOn(s_agent.Agent, only_query='id', required=True, comment=m.Trade.to_comment)
to = NestedOn(s_agent.Agent, only_query='id', required=True, comment=m.Trade.user_to_comment)
confirms = NestedOn(Organize)