This commit is contained in:
Andrey Makhnach 2013-06-15 01:33:52 +03:00
parent 9a3d1ad45b
commit ad42553303
4 changed files with 18 additions and 15 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 @@
import os
from flask import Flask
from flask.ext.admin import Admin
from flask.ext.admin.contrib.sqlamodel import ModelView
from pytest_bdd_example.dashboard import settings
from pytest_bdd_example.auth import auth
from pytest_bdd_example.book import book, Author, Book, db as book_db
from pytest_bdd_example.book import book
app = Flask(
@ -19,6 +16,4 @@ app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'
app.register_blueprint(auth, url_prefix='/auth')
admin = Admin(app)
admin.add_view(ModelView(Book, book_db.Session(), 'books', endpoint='books'))
app.register_blueprint(book, url_prefix='/book')