以下代码正常运行。
import datetime
from flask import Flask
from peewee import TextField, DateTimeField
from flask_peewee.db import Database
from flask_peewee.auth import Auth
from flask_peewee.admin import Admin, ModelAdmin
# configure database
DATABASE = {
'name': 'surveyApp.db',
'engine': 'peewee.SqliteDatabase',
}
DEBUG = True
CSRF_ENABLED = True
SECRET_KEY = 'you-will-never-guess'
app = Flask(__name__)
app.config.from_object(__name__)
db = Database(app)
# from model.user_infos import Note, NoteAdmin
class Note(db.Model):
message = TextField()
created = DateTimeField(default=datetime.datetime.now)
class NoteAdmin(ModelAdmin):
columns = ('message', 'created',)
# create an Auth object for use with our flask app and database wrapper
auth = Auth(app, db)
admin = Admin(app, auth)
admin.register(Note, NoteAdmin)
admin.setup()
if __name__ == '__main__':
app.run()
我正在尝试将模型分开并在管理员中注册它。但它产生了错误。所有型号都在内部'模型'文件夹中。
import datetime
from flask import Flask
from peewee import TextField, DateTimeField
from flask_peewee.db import Database
from flask_peewee.auth import Auth
from flask_peewee.admin import Admin, ModelAdmin
# configure database
DATABASE = {
'name': 'surveyApp.db',
'engine': 'peewee.SqliteDatabase',
}
DEBUG = True
CSRF_ENABLED = True
SECRET_KEY = 'you-will-never-guess'
app = Flask(__name__)
app.config.from_object(__name__)
db = Database(app)
auth = Auth(app, db)
admin = Admin(app, auth)
from model.user_infos import Note, NoteAdmin # GENERATES IMPORT ERROR
admin.register(Note, NoteAdmin)
admin.setup()
if __name__ == '__main__':
app.run()
from run import db, admin
import datetime
from peewee import TextField, DateTimeField
from flask_peewee.admin import ModelAdmin
class Note(db.Model):
message = TextField()
created = DateTimeField(default=datetime.datetime.now)
class NoteAdmin(ModelAdmin):
columns = ('message', 'created',)
模型文件夹也包含__init__.py
答案 0 :(得分:1)