def admin_files_managing(): from apps.main import admin files_dir = os.path.join(BASE_DIR, "static") for view in admin._views: if isinstance(view, MyFileAdmin): break else: admin.add_view(MyFileAdmin(files_dir, endpoint="myfileadmin"))
from flask_admin.contrib.sqla import ModelView from apps.comments.models import Comment from apps.main.admin import ProtectedAdminView from apps.main import db, admin class CommentView(ProtectedAdminView, ModelView): @property def display_home(self): return True admin.add_view(CommentView(Comment, db.session))
'comments': { 'fields': [Comment.author_name, Comment.author_email], 'page_size': 10 } } form_widget_args = { 'slug': { 'disabled': True }, 'description': { 'rows': 20 }, 'timestamp': { 'disabled': True } } inline_models = [InlinePlacePic(PlaceImage)] class ImagesView(PicUploadWithThumbnail, ProtectedAdminView, ModelView): @property def display_home(self): return True form_widget_args = {'thumbnail': {'disabled': True}} admin.add_view(PlaceView(Place, db.session)) admin.add_view(ImagesView(PlaceImage, db.session))
class UserView(ProtectedAdminView, ModelView): column_display_pk = True form_widget_args = { 'password_hash': { 'disabled': True }, 'confirmed': { 'style': 'width: 20px' } } form_ajax_refs = { 'groups': { 'fields': (UserGroup.name,), } } @property def display_home(self): return True class GroupView(ProtectedAdminView, ModelView): @property def display_home(self): return True admin.add_view(UserView(User, db.session)) admin.add_view(GroupView(UserGroup, db.session))
from apps.main.admin import ProtectedAdminView from apps.main import db, admin from apps.places.models import Place from apps.comments.models import Comment class ModelViewSec(ProtectedAdminView, ModelView): @property def display_home(self): return True form_columns = [ 'title', 'slug', 'price', 'duration', 'min_people_number', 'distance' ] form_widget_args = {'slug': {'disabled': True}} form_ajax_refs = { 'places': { 'fields': [Place.title], 'page_size': 10 }, 'comments': { 'fields': [Comment.author_name, Comment.author_email], 'page_size': 5 } } admin.add_view(ModelViewSec(Tour, db.session))