syrusakbary / Flask-SuperAdmin

The best admin interface framework for Flask. With scaffolding for MongoEngine, Django and SQLAlchemy.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

One-to-One (using uselist=False) does not work.

suzanshakya opened this issue · comments

Hi,
I defined a one-to-one relationship for models User and Profile using uselist=False, and registered each model with superadmin. After inserting one data in each model, and creating one-to-one link, when I browse http://127.0.0.1:5000/admin/user/1/, I get this error "TypeError: argument of type 'Profile' is not iterable".

This flask app can be run to reproduce this error.

from flask import Flask
from flask.ext.superadmin import Admin
from flask.ext.sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///superadmin.db"
app.config["SECRET_KEY"] = "bug"
admin = Admin(app)
db = SQLAlchemy(app)

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(64), nullable=False, unique=True)
    password = db.Column(db.String(64))
    fullname = db.Column(db.String(64))

    def __repr__(self):
        return "<User: %s>" % self.fullname

class Profile(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey("user.id"))
    user = db.relationship("User", backref=db.backref("profile", uselist=False))

    def __repr__(self):
        return "<Profile: %s>" % self.user

db.create_all()

# Create Admin views
for model in [User, Profile]:
    admin.register(model, session=db.session)

app.run(debug=True)

Having the same issue with the same setup. Did you ever figure it out or is this a critical bug with no workaround?