try solve problems with foreignkey
This commit is contained in:
parent
2ec03d962e
commit
c5e62914b6
|
@ -29,6 +29,7 @@ def get_inv():
|
||||||
raise ValueError("Inventory value is not specified")
|
raise ValueError("Inventory value is not specified")
|
||||||
return INV
|
return INV
|
||||||
|
|
||||||
|
|
||||||
def upgrade():
|
def upgrade():
|
||||||
# Document table
|
# Document table
|
||||||
op.create_table('document',
|
op.create_table('document',
|
||||||
|
@ -58,16 +59,15 @@ def upgrade():
|
||||||
|
|
||||||
# ToErased table
|
# ToErased table
|
||||||
op.create_table('to_erased',
|
op.create_table('to_erased',
|
||||||
# sa.Column('document_id', sa.BigInteger(), nullable=True),
|
sa.Column('document_id', sa.BigInteger(), nullable=False),
|
||||||
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||||
# sa.ForeignKeyConstraint(['document_id'], [f'{get_inv()}.document.id'], ),
|
sa.ForeignKeyConstraint(['document_id'], [f'{get_inv()}.document.id'], ),
|
||||||
sa.ForeignKeyConstraint(['id'], [f'{get_inv()}.action.id'], ),
|
sa.ForeignKeyConstraint(['id'], [f'{get_inv()}.action.id'], ),
|
||||||
sa.PrimaryKeyConstraint('id'),
|
sa.PrimaryKeyConstraint('id'),
|
||||||
schema=f'{get_inv()}'
|
schema=f'{get_inv()}'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
op.drop_table('to_erased', schema=f'{get_inv()}')
|
op.drop_table('to_erased', schema=f'{get_inv()}')
|
||||||
op.drop_table('document', schema=f'{get_inv()}')
|
op.drop_table('document', schema=f'{get_inv()}')
|
||||||
|
|
|
@ -1332,16 +1332,24 @@ class ToErased(ActionWithMultipleDevices):
|
||||||
"""
|
"""
|
||||||
document_comment = """The user that gets the device due this deal."""
|
document_comment = """The user that gets the device due this deal."""
|
||||||
# document_id = db.Column(BigInteger,
|
# document_id = db.Column(BigInteger,
|
||||||
# db.ForeignKey('document.id',
|
# db.ForeignKey('document.id'),
|
||||||
# use_alter=True,
|
# nullable=False)
|
||||||
# name='document'),
|
# document = db.relationship('EraseDocument',
|
||||||
# nullable=False)
|
# backref=backref('actions',
|
||||||
# document = relationship('EraseDocument',
|
# # lazy=True,
|
||||||
# backref=backref('actions',
|
# # uselist=False,
|
||||||
# lazy=True,
|
# # cascade=CASCADE_OWN),
|
||||||
# uselist=False,
|
# uselist=True,
|
||||||
# cascade=CASCADE_OWN),
|
# lazy=True,
|
||||||
# primaryjoin='ToErased.document_id == EraseDocument.id')
|
# order_by=lambda: Action.end_time,
|
||||||
|
# collection_class=list),
|
||||||
|
# primaryjoin='ToErased.document_id == EraseDocument.id')
|
||||||
|
document_id = Column(BigInteger, ForeignKey('document.id'), nullable=False)
|
||||||
|
document = relationship('Document',
|
||||||
|
backref=backref('document_one',
|
||||||
|
lazy=True,
|
||||||
|
cascade=CASCADE_OWN),
|
||||||
|
primaryjoin='ToErased.document_id == Document.id')
|
||||||
|
|
||||||
|
|
||||||
class Prepare(ActionWithMultipleDevices):
|
class Prepare(ActionWithMultipleDevices):
|
||||||
|
|
|
@ -432,6 +432,8 @@ class Prepare(ActionWithMultipleDevices):
|
||||||
|
|
||||||
class ToErased(ActionWithMultipleDevices):
|
class ToErased(ActionWithMultipleDevices):
|
||||||
__doc__ = m.ToErased.__doc__
|
__doc__ = m.ToErased.__doc__
|
||||||
|
document = NestedOn('Document', only_query='id')
|
||||||
|
# device = NestedOn(s_device.Device, only_query='id')
|
||||||
|
|
||||||
|
|
||||||
class Live(ActionWithOneDevice):
|
class Live(ActionWithOneDevice):
|
||||||
|
|
|
@ -52,12 +52,15 @@ class ErasedView():
|
||||||
doc_data['type'] = 'ToErased'
|
doc_data['type'] = 'ToErased'
|
||||||
self.document = EraseDocument(**doc_data)
|
self.document = EraseDocument(**doc_data)
|
||||||
db.session.add(self.document)
|
db.session.add(self.document)
|
||||||
db.session.commit()
|
# db.session.commit()
|
||||||
|
|
||||||
def insert_action(self, data):
|
def insert_action(self, data):
|
||||||
import pdb; pdb.set_trace()
|
import pdb; pdb.set_trace()
|
||||||
[data.pop(x, None) for x in ['url', 'documentId', 'filename', 'hash']]
|
[data.pop(x, None) for x in ['url', 'documentId', 'filename', 'hash']]
|
||||||
self.data = self.schema.load(data)
|
# self.data = self.schema.load(data)
|
||||||
|
# self.data['document_id'] = self.document.id
|
||||||
# self.data['document'] = self.document
|
# self.data['document'] = self.document
|
||||||
self.erased = ToErased(**self.data)
|
# data['document_id'] = self.document.id
|
||||||
|
data['document'] = self.document
|
||||||
|
self.erased = ToErased(**data)
|
||||||
db.session.add(self.erased)
|
db.session.add(self.erased)
|
||||||
|
|
|
@ -21,7 +21,7 @@ class Document(Thing):
|
||||||
date = Column(db.DateTime, nullable=True)
|
date = Column(db.DateTime, nullable=True)
|
||||||
date.comment = """The date of document, some documents need to have one date
|
date.comment = """The date of document, some documents need to have one date
|
||||||
"""
|
"""
|
||||||
id_document = Column(CIText(), nullable=True)
|
id_document = Column(CIText(), nullable=False)
|
||||||
id_document.comment = """The id of one document like invoice so they can be linked."""
|
id_document.comment = """The id of one document like invoice so they can be linked."""
|
||||||
owner_id = db.Column(UUID(as_uuid=True),
|
owner_id = db.Column(UUID(as_uuid=True),
|
||||||
db.ForeignKey(User.id),
|
db.ForeignKey(User.id),
|
||||||
|
|
Reference in New Issue