How to display versioned data (SQLAlchemy-Continuum) in Flask-admin

803 views Asked by At

I'm using SQLAlchemy-Continuum for versioning the data records of one of my sqlalchemy-objects.

Examplecode:

class Assessment(db.Model):
__versioned__ = {}
__tablename__ = "assesment_table"
id = db.Column(db.Integer, primary_key=True)
rating = db.Column(db.Float)
assessment_date_id = db.Column(db.String(20), db.ForeignKey("assessment_dates_table.assessment_date_id"))
assessment_date = db.relationship("AssessmentDate")
comment = db.Column(db.String(400))
status = db.Column(db.String(40))
created_at = db.Column(db.DateTime(timezone=True), server_default=func.now())
last_updated = db.Column(db.DateTime(timezone=True), onupdate=func.now())
last_updated_by = db.Column(db.String(80))

to see the table in the flask_admin-dashboard I use the following code:

admin.add_view(AssessmentView(Assessment, db.session))

But how can I add the versioned history table to the flask admin dashboard? When I connect directly to my mariaDB, I can see the table and versioned data records.

any help is highly appreciated. Thank you a lot! Best regards Simon

1

There are 1 answers

0
Simon On

with the following code you can add a view for your history_table to your flask-admin dashboard:

from sqlalchemy_continuum import version_class

ClassVersion = version_class(<Your Class>)
admin.add_view(ModelView(ClassVersion, db.session))

I hope this helps

Regards Simon