本文整理汇总了Python中flask_peewee.admin.Admin类的典型用法代码示例。如果您正苦于以下问题:Python Admin类的具体用法?Python Admin怎么用?Python Admin使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Admin类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_app
def create_app(settings_override=None):
app = factory.create_app(__name__, __path__, settings_override)
admin = Admin(app, auth)
register_admin(admin)
admin.setup()
return app
示例2: setup_admin
def setup_admin():
auth = Auth(app, db)
admin = Admin(app, auth)
admin.register(Note, NoteAdmin)
admin.register(Author, AuthorAdmin)
auth.register_admin(admin)
admin.setup()
return auth, admin
示例3: CharField
description = CharField(max_length=2000, null=True)
url = CharField()
price = DecimalField(max_digits=10, decimal_places=2)
wishlist = ForeignKeyField(WishList, related_name='items')
numberOfParts = IntegerField()
class Part(db.Model):
"""
A part is the smallest subdivision of an item.
Thanks to this, an item can be bought by several different users.
"""
user = ForeignKeyField(auth.User, related_name='gifts')
item = ForeignKeyField(Item, related_name='parts')
# admin part
admin = Admin(app, auth)
admin.register(WishList)
admin.register(Item)
admin.register(Part)
# api part
user_auth = UserAuthentication(auth)
api = RestAPI(app, default_auth=user_auth)
api.register(WishList)
api.register(Item, ItemResource)
api.register(Part)
# setup
示例4: Admin
# -*- coding: utf-8 -*-
"""
admin imports app, auth and models, but none of these import admin
so we're OK
"""
from flask_peewee.admin import Admin, ModelAdmin
from app import app, db
from auth import auth
from models import User
admin = Admin(app, auth)
# auth.register_admin(admin)
admin.register(User, ModelAdmin)
# register any other models here.
示例5: Admin
from flask_peewee.admin import Admin, ModelAdmin
from app import app, db
from auth import auth
from models import User, Location, Acl
from pbkdf2 import hashing_passwords as hp
admin = Admin(app, auth, branding='ownTracks')
# Check for existing admin user and in none
# exists create one
# TODO: Show flash message for newly created
# admin user
try:
test_admin = User.get(User.username == 'admin')
except:
# No Admin user yet, so create one
test_admin = auth.User(username='admin', email='', admin=True, active=True, superuser=True)
test_admin.set_password('admin')
test_admin.save()
# or you could admin.register(User, ModelAdmin) -- you would also register
# any other models here.
class LocationAdmin(ModelAdmin):
columns = ('tst', 'username', 'device', 'lat', 'lon', )
class UserAdmin(ModelAdmin):
columns = ('username', 'superuser', 'pbkdf2',)
示例6: DateField
day = DateField(default=datetime.date.today, unique=True, verbose_name="Dzien")
soup = CharField(null=True, verbose_name="Zupa")
main_dish = CharField(null=True, verbose_name="Drugie danie")
def __str__(self):
return "%s - %s - %s" % (self.day, self.soup, self.main_dish)
Obiad.create_table(fail_silently=True)
class Cytat(db.Model):
timestamp = DateTimeField(default=datetime.datetime.now(), verbose_name="Czas dodania")
content = TextField(unique=True, verbose_name="Tresc")
def __str__(self):
return self.content
Cytat.create_table(fail_silently=True)
auth = Auth(app, db)
auth.User.create_table(fail_silently=True)
admin = Admin(app, auth)
auth.register_admin(admin)
admin.register(Przedmiot)
class PracaDomowaAdmin(ModelAdmin):
columns = ('deadline', 'subject', 'short_name', 'description', 'checked',)
admin.register(PracaDomowa, PracaDomowaAdmin)
class SprawdzianAdmin(ModelAdmin):
columns = ('date', 'subject', 'short_name', 'description', 'done',)
admin.register(Sprawdzian, SprawdzianAdmin)
class ObiadAdmin(ModelAdmin):
columns = ('day', 'soup', 'main_dish',)
admin.register(Obiad, ObiadAdmin)
class CytatAdmin(ModelAdmin):
columns = ('content',)
admin.register(Cytat, CytatAdmin)
admin.setup()
示例7: redirect
if request.form.get('message'):
Note.create(
user=auth.get_logged_in_user(),
message=request.form['message'],
)
next = request.form.get('next') or self.dashboard_url()
return redirect(next)
def get_context(self):
return {
'note_list': Note.select().order_by(('created_date', 'desc')).paginate(1, 3)
}
auth = Auth(app, db, user_model=User)
admin = Admin(app, auth)
class AAdmin(ModelAdmin):
columns = ('a_field',)
class BAdmin(ModelAdmin):
columns = ('a', 'b_field',)
include_foreign_keys = {'a': 'a_field'}
class CAdmin(ModelAdmin):
columns = ('b', 'c_field',)
include_foreign_keys = {'b': 'b_field'}
class DAdmin(ModelAdmin):
columns = ('c', 'd_field',)
示例8: EntryAdmin
from flask import request, redirect
from auth import auth
from models import *
from app import app, psql_db
class EntryAdmin(ModelAdmin):
columns = ('title', 'publishdate', 'recipe', 'private')
def get_query(self):
return Entry.select().order_by(-Entry.publishdate)
class UserAdmin(ModelAdmin):
columns = ('username', 'email', 'twitter', 'admin', 'active')
class RecipeAdmin(ModelAdmin):
def get_query(self):
return Recipe.select().order_by(Recipe.slug)
class PageAdmin(ModelAdmin):
def get_query(self):
return Page.select().order_by(-Page.publishdate)
admin = Admin(app, auth, branding = "Carboy admin")
auth.register_admin(admin)
admin.register(Entry, EntryAdmin)
admin.register(Page, PageAdmin)
admin.register(Recipe, RecipeAdmin)
admin.register(User, UserAdmin)
admin.setup()
示例9: Admin
from flask_peewee.admin import Admin
from gistsurfr.app import app, db
from gistsurfr.auth import auth
from gistsurfr.models import User, UserRelationship, UserGithub, UserGistFavorite
admin = Admin(app, auth, branding='Gistsurfr')
auth.register_admin(admin)
admin.register(UserRelationship)
admin.register(UserGithub)
admin.register(UserGistFavorite)
示例10: UserView
from flask_peewee.admin import Admin, ModelAdmin
from app import app
from auth import auth
from models import User
class UserView(ModelAdmin):
columns = ('username', 'email',)
admin = Admin(app, auth)
auth.register_admin(admin)
admin.register(User, UserView)
admin.setup()
示例11: CarAdmin
from flask_peewee.admin import Admin, ModelAdmin
from app import app, db
from auth import auth
from models import *
class CarAdmin(ModelAdmin):
columns = ('user', 'vehicle_id', 'model', 'year', 'name', 'picture');
class CommuteAdmin(ModelAdmin):
columns = ('car', 'trip_mpg', 'trip_milage', 'duration')
class CBSMessageAdmin(ModelAdmin):
columns = ('car', 'type', 'state', 'description', 'remaining_mileage', 'due_date', 'update_time')
class CCMMessageAdmin(ModelAdmin):
columns = ('car', 'ccm_id', 'mileage', 'description', 'update_time')
class RawDataAdmin(ModelAdmin):
columns = ('car', 'update_time', 'tank_level', 'fuel_range', 'fuel_reserve', 'odometer', 'ave_mpg', 'headlights', 'speed', 'engine_status')
admin = Admin(app, auth)
auth.register_admin(admin)
admin.register(Car, CarAdmin)
admin.register(RawData, RawDataAdmin)
admin.register(CCMMessage, CCMMessageAdmin)
admin.register(CBSMessage, CBSMessageAdmin)
admin.register(Commute, CommuteAdmin)
示例12: UserStatsPanel
}
class UserStatsPanel(AdminPanel):
template_name = 'admin/user_stats.html'
def get_context(self):
last_week = datetime.datetime.now() - datetime.timedelta(days=7)
signups_this_week = User.filter(join_date__gt=last_week).count()
messages_this_week = Message.filter(pub_date__gt=last_week).count()
return {
'signups': signups_this_week,
'messages': messages_this_week,
}
admin = Admin(app, auth)
class MessageAdmin(ModelAdmin):
columns = ('user', 'content', 'pub_date',)
foreign_key_lookups = {'user': 'username'}
filter_fields = ('user', 'content', 'pub_date', 'user__username')
class NoteAdmin(ModelAdmin):
columns = ('user', 'message', 'created_date',)
exclude = ('created_date',)
class CityAdmin(ModelAdmin):
columns = ('name',)
class PincheAdmin(ModelAdmin):
columns = ('city', 'title', 'phone', 'route', 'publisher', 'content',)
示例13: home
Model.create_table(fail_silently=True)
user_datastore.create_user(email='[email protected]', password='password')
# Views
@app.route('/')
@login_required
def home():
return render_template('index.html')
# needed for authentication
auth = Auth(app, db)
class MessageAdmin(ModelAdmin):
columns = ('user', 'content', 'pub_date')
class Message(db.Model):
user = ForeignKeyField(User)
content = TextField()
pub_date = DateTimeField(default=datetime.datetime.now)
def __unicode__(self):
return '%s: %s' % (self.user, self.content)
admin = Admin(app, auth)
admin.register(Message, MessageAdmin)
admin.setup()
app.run(host = '0.0.0.0',
port = 8080,
debug = True,
threaded = True)
示例14: flash
if form.validate_on_submit():
flash("User Created", "success")
models.Taco.create(user=g.user._get_current_object(),
phoneNumber=form.phoneNumber.data,
fullName=form.fullName.data,
email=form.email.data,
member=form.member.data)
return redirect(url_for('signIn'))
return render_template('signup.html', form=form)
if __name__ == '__main__':
models.initialize()
admin = Admin(app, name="Temple")
admin.add_view(MyModelView(models.User))
admin.add_view(MyModelView(models.Taco, name="Member Info"))
admin.add_view(MyModelView(models.Check))
try:
models.User.create_user(
email='[email protected]',
password='password',
admin = True
)
except ValueError:
pass
app.run(debug=DEBUG, host=HOST, port=PORT)
示例15: init_admin
def init_admin(app, auth, models):
admin = Admin(app, auth)
for model in models:
admin.register(model)
admin.setup()