Search code examples
pythonflask-admin

Flask-Admin : Missing Foreign Key Field


I'm currently starting a project and need to manage my database anytime so I used the Flask-Admin plugin. It works pretty nice for now except for one point and I don't know what's wrong.
Simplifying my database, I have Users and Movies. Users can post a Review about a Movie. So here is my review class :

# -*- coding: utf-8 -*-

from app import db
from app import admin

class Review(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    note = db.Column(db.Integer)
    critic = db.Column(db.String)

    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    movie_id = db.Column(db.Integer, db.ForeignKey('movie.id'))

The only problem I have is that my Flask-Admin page when creating and editing a Review doesn't show the user_id field. I don't know why... What am I doing wrong here ?


Solution

  • I did forget to declare the backref attribute in my User model for the Reviews.