flask admin forgeign keys show literal

  1. Import necessary modules and classes:
from flask_admin.contrib.sqla import ModelView
from your_application import db, YourModel
  1. Create a custom ModelView class:
class CustomModelView(ModelView):
    column_display_pk = True  # Display primary keys in the list view
  1. Define your Flask application:
from flask import Flask
app = Flask(__name__)
  1. Configure the Flask application with your database:
app.config['SQLALCHEMY_DATABASE_URI'] = 'your_database_uri_here'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
  1. Initialize the Flask-Admin extension and add views for your models:
from flask_admin import Admin

admin = Admin(app, name='YourApp', template_mode='bootstrap3')
admin.add_view(CustomModelView(YourModel, db.session))
  1. Run the Flask application:
if __name__ == '__main__':
    app.run(debug=True)

Ensure that you replace 'your_database_uri_here' with the actual URI of your database and YourModel with the name of your SQLAlchemy model.