Tuesday 15 May 2012

python - Unable to create models on Flask-admin -


I am creating a simple blog on the flask and I try to apply the flask-admin to manage my posts I am doing If I go to the administration area, then I can get a list of all my posts from DB, but when I try to create a new one, I get the next error:

  failed to make model . This is my post model:  
  class post (DB model): __tablename__ = 'news' Nid = db.Column Primary_key = true) title = db.Column (db.String (100)) content = db.Column (db.Text) created_att = db Column (db.DateTime) def __init__ (auto, title, content): self.title = title.title () self.content = content self.created_at = datetime.datetime.now ()   < P> And this is my code Add u's model:  
  Flask from flask import, session import db from the post, post from flask. Import.admin import flask.ext.admin ModelView app = bottle (__name__) app.config from contrib.sqlamodel ['SQLALCHEMY_DATABASE_URI'] = 'mysql: // root: pass @ local host / APPNAME' db.init_app (application) admin = admin (application) admin Add_view (ModelView (post, db.session))   

I can edit the model through the admin panel but can not make new I know that I'm really missing something stupid, but I can not understand what it is.

EDIT: This works if I do not apply init to the model how can I fix it?

Look for the corresponding section in the source code for the flask-admin.

The model is created without passing any argument:

  model = self.model ()   

So what's your Support a producer who does not take any debate

  def __init __ (self, title = "", content = "") :: self.title = title, for example, Code> __init __  declaration of the manufacturer with default argument. Title () self.content = content self.created_at = datetime.datetime.now ()    

No comments:

Post a Comment