Commit 5ce29d1c authored by Serge S. Koval's avatar Serge S. Koval

Updated examples, added wysiwyg example

parent 6a530760
......@@ -2,7 +2,7 @@ Flask-Admin
===========
.. image:: https://travis-ci.org/mrjoes/flask-admin.png?branch=master
:target: https://secure.travis-ci.org/mrjoes/flask-admin
:target: https://travis-ci.org/mrjoes/flask-admin
Introduction
......@@ -35,4 +35,4 @@ Some ideas were taken from the `Flask-Admin <https://github.com/wilsaj/flask-adm
Examples
--------
The library comes with a few examples, you can find them in the `examples` directory.
The library comes with a few examples, you can find them in the `examples <https://github.com/mrjoes/flask-admin/tree/master/examples` directory.
This example shows how to integrate Flask-Login authentication with the Flask-Admin using MongoEngine backend.
This example shows how to integrate Flask-Login authentication with the Flask-Admin using SQLAlchemy backend.
......@@ -4,7 +4,7 @@ from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext import admin, login, wtf
from flask.ext.admin.contrib import sqlamodel
# Create application
# Create Flask application
app = Flask(__name__)
# Create dummy secrey key so we can use sessions
......
This example show how to translate Flask-Admin into different language using customized version of the `Flask-Babel <https://github.com/mrjoes/flask-babel>`
\ No newline at end of file
Simple file management interface example.
\ No newline at end of file
External menu links example.
\ No newline at end of file
Example which shows how to integrate Flask `MethodView` with Flask-Admin.
\ No newline at end of file
from flask import Flask, redirect, render_template, request
from flask import Flask, redirect, request
from flask.ext import admin
from flask.views import MethodView
......@@ -13,6 +13,7 @@ class ViewWithMethodViews(admin.BaseView):
class API_v1(MethodView):
def get(self, cls):
return cls.render('test.html', request=request, name="API_v1")
def post(self, cls):
return cls.render('test.html', request=request, name="API_v1")
......@@ -20,9 +21,11 @@ class ViewWithMethodViews(admin.BaseView):
class API_v2(MethodView):
def get(self, cls):
return cls.render('test.html', request=request, name="API_v2")
def post(self, cls):
return cls.render('test.html', request=request, name="API_v2")
# Create flask app
app = Flask(__name__, template_folder='templates')
......
MongoEngine model backend integration.
\ No newline at end of file
......@@ -18,6 +18,7 @@ db = MongoEngine()
db.init_app(app)
# Define mongoengine documents
class User(db.Document):
name = db.StringField(max_length=40)
tags = db.ListField(db.ReferenceField('Tag'))
......
This example shows how to create two separate instances of Flask-Admin for one Flask application.
\ No newline at end of file
Peewee model backend integration example.
\ No newline at end of file
PyMongo model backend integration example.
\ No newline at end of file
Simple Flask-Admin examples used by the quickstart tutorial.
\ No newline at end of file
SQLAlchemy model backend integration example.
\ No newline at end of file
Simple CKEditor integration example.
\ No newline at end of file
import datetime
from sqlalchemy.ext.hybrid import hybrid_property
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext import admin, wtf
from flask.ext.admin.contrib import sqlamodel
from flask.ext.admin.contrib.sqlamodel import filters
# Create application
app = Flask(__name__)
# Create dummy secrey key so we can use sessions
app.config['SECRET_KEY'] = '123456790'
# Create in-memory database
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///dummy.sqlite'
app.config['SQLALCHEMY_ECHO'] = True
db = SQLAlchemy(app)
# Define wtforms widget and field
class CKTextAreaWidget(wtf.TextArea):
def __call__(self, field, **kwargs):
kwargs.setdefault('class_', 'ckeditor')
return super(CKTextAreaWidget, self).__call__(field, **kwargs)
class CKTextAreaField(wtf.TextAreaField):
widget = CKTextAreaWidget()
# Model
class Page(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.Unicode(64))
text = db.Column(db.UnicodeText)
def __unicode__(self):
return self.name
# Customized admin interface
class PageAdmin(sqlamodel.ModelView):
form_overrides = dict(text=CKTextAreaField)
create_template = 'create.html'
edit_template = 'edit.html'
# Flask views
@app.route('/')
def index():
return '<a href="/admin/">Click me to get to Admin!</a>'
if __name__ == '__main__':
# Create admin
admin = admin.Admin(app)
# Add views
admin.add_view(PageAdmin(Page, db.session))
# Create DB
db.create_all()
# Start app
app.debug = True
app.run('0.0.0.0', 8000)
{% extends 'admin/model/create.html' %}
{% block tail %}
{{ super() }}
<script src="http://cdnjs.cloudflare.com/ajax/libs/ckeditor/4.0.1/ckeditor.js"></script>
{% endblock %}
{% extends 'admin/model/create.html' %}
{% block tail %}
{{ super() }}
<script src="http://cdnjs.cloudflare.com/ajax/libs/ckeditor/4.0.1/ckeditor.js"></script>
{% endblock %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment