Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
suzanshakya opened this issue Jun 27, 2014 · 1 comment
Open

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

suzanshakya opened this issue Jun 27, 2014 · 1 comment

Comments

@suzanshakya
Copy link

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)
@Deathnerd
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants