This commit is contained in:
Oleg Podsadny 2013-06-15 00:36:49 +02:00
commit 76a06cdcb4
4 changed files with 18 additions and 17 deletions

View File

@ -0,0 +1,6 @@
from flask.ext.admin import Admin
from flask.ext.admin.contrib.sqlamodel import ModelView
from pytest_bdd_example.book import Book, db
admin = Admin()
admin.add_view(ModelView(Book, db.Session(), 'books', endpoint='books'))

View File

@ -1,6 +1,7 @@
from flask import Blueprint
from .models import db
from .admin import admin
book = Blueprint('book', __name__, template_folder='../')
@ -8,3 +9,4 @@ book = Blueprint('book', __name__, template_folder='../')
@book.record_once
def on_registered(state):
db.init_app(state.app)
admin.init_app(state.app)

View File

@ -9,6 +9,14 @@ association_table = db.Table('association', Base.metadata,
db.Column('right_id', db.Integer, db.ForeignKey('right.id'))
)
class Author(db.Model):
id = db.Column(db.Integer, primary_key=True)
first_name = db.Column(db.String(30))
last_name = db.Column(db.String(30))
sur_name = db.Column(db.String(30))
class Book(db.Model):
id = db.Column(db.Integer, primary_key=True)
@ -16,11 +24,3 @@ class Book(db.Model):
description = db.Column(db.Text)
authors = db.relationship("Author", secondary=association_table, backref="books", order_by="Author.id")
class Author(db.Model):
id = db.Column(db.Integer, primary_key=True)
first_name = db.Column(db.String(30))
last_name = db.Column(db.String(30))
sur_name = db.Column(db.String(30))

View File

@ -1,12 +1,9 @@
from flask import Flask
from flask.ext.admin import Admin
from flask.ext.admin.contrib.sqlamodel import ModelView
from flask.ext.sqlalchemy import SQLAlchemy
from pytest_bdd_example.dashboard import settings
from pytest_bdd_example.auth import auth
from pytest_bdd_example.book import book, Book
from pytest_bdd_example.book import book
app = Flask(
@ -17,10 +14,6 @@ app = Flask(
app.config.from_object('pytest_bdd_example.dashboard.settings')
app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'
db = SQLAlchemy(app)
app.register_blueprint(auth, url_prefix='/auth')
app.register_blueprint(book)
admin = Admin(app)
admin.add_view(ModelView(Book, db.Session(), 'books', endpoint='books'))
app.register_blueprint(book, url_prefix='/book')