flask-admin

limit choices with dropdown in flask-admin

给你一囗甜甜゛ 提交于 2019-12-03 06:05:35
My SQLAlchemy model has a String field that I would like to limit to a few choices. I am wondering how I would be able to create a dropdown for this field in the Flask-Admin interface that would ensure that the db is only populated with one of my choices. If I let the user manually enter these fields, they may spell them incorrectly, etc. enum , form_choices and form_args Your question is about restricting values at the form level, but we can also briefly discuss it at the schema level. A. Restricting Values at the Database Level: enum fields To limit the range of allowable values, the first

Flask-Admin default filters

匿名 (未验证) 提交于 2019-12-03 01:52:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I would like to display only paid orders in my Flask-Admin model list view. Here is models.py: class Order(db.Model): id = db.Column(db.Integer, primary_key=True) amount = db.Column(db.Integer) description = db.Column(db.String) paid = db.Column(db.Boolean, default=False) Here is ModelView for Flask-Admin: class OrderView(ModelView): column_filters = ("paid") admin.add_view(OrderView(Order, db.session)) Filters work fine, but I would like to make this filter default. Or better yet, do not use filters, and only show orders that are output of

How do you add a summary row for Flask-Admin?

一个人想着一个人 提交于 2019-12-02 00:47:11
In my flask-admin index_view, I am displaying financial information for my rows. I would like to add an extra row, "summary row", at the bottom of my index_view table which sums up all the columns. How can I accomplish this? There's a couple of things you need to do. Provide a custom list.html template and override the render() method for the view. In the render method inject your summary data into the kwargs and in the custom template use the summary data to output appropriate html. You could add the summary data to the end of the existing data table or add it to a separate table, as seen in

flask-admin is_accessible usage

主宰稳场 提交于 2019-12-01 21:26:29
I've checked the docs and It's pretty vague how the is_accessible method should be implemented. Here is what the docs of flask admin showed class MicroBlogModelView(sqla.ModelView): def is_accessible(self): return login.current_user.is_authenticated() def inaccessible_callback(self, name, **kwargs): # redirect to login page if user doesn't have access return redirect(url_for('login', next=request.url)) what I don't get though is how do you call it is it automatically called or do you have to call it yourself like this: @expose("/", methods=["GET", "POST"]) def home(self): if self.is_accesible(

flask-admin: how to allow only super users can view the specified table column?

纵饮孤独 提交于 2019-12-01 07:32:45
问题 I've built an app with a table called Project which is stored in sqlite, I want allow only super users can view the approve column when creating, editing data. The Project data is retrieved in the "class Project" , and I've added if current_user.has_role('superuser') in "class ProjectView" : from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_security import SQLAlchemyUserDatastore, current_user,UserMixin, RoleMixin from flask_admin.contrib import sqla # Create Flask

Flask-Admin different forms and column_list for different roles

て烟熏妆下的殇ゞ 提交于 2019-12-01 04:33:54
问题 Following up on this question Flask-Admin Role Based Access - Modify access based on role I don't understand how to implement role-based views, especially regarding the form and column_lists. Say I want MyModelView to show different columns if the user is a regular user or a superuser. Overriding is_accessible in MyModelView has no effect at all from flask_security import Security, SQLAlchemyUserDatastore, current_user class MyModelView(SafeModelView): # ... def is_accessible(self): if

Hiding fields in Flask-Admin depending on logged in user?

南楼画角 提交于 2019-12-01 01:21:16
I have Users and Roles in my Flask app thanks to Flask-Security. For some roles I would like to hide certain fields in the forms created by Flask-Admin. I know about customizing ModelViews with eg. form_create_rules = ('title', 'file') but while instantiating a ModelView there isn't access to the current request so current_user.has_role(USER_ROLE) can't be called. Is there any other way to achieve this? pjcunningham One way of achieving this is to create multiple view classes and register these view classes against their appropriate roles. See this answer on how to register roles to views.

Flask-Admin Many-to-Many field display

半城伤御伤魂 提交于 2019-11-30 14:29:36
问题 I develop an application using Flask. I use Postgres db (psycop2), SQLAlchemy and Flask-Admin for admin interface. And I got a problem and can't find a solution. I have many-to-many relationship between articles and tags tables it's clear. In the Flask-Admin interface when I try to add a tag to articel (or vise versa) it works fine. But it displays awfully and it impossible to choose correct tag because it displays like an object: And that is right because it is an instance of my model class.

DatePickerWidget with Flask, Flask-Admin and WTforms

蹲街弑〆低调 提交于 2019-11-29 21:53:37
I'm trying to render a template that contains a DatePicker, but I'm getting a 500 error when I try. For my the code is correct, but it seems that something is failing or I'm not understanding correctly the way to do it. The code is the following: Reporting.py from flask.ext.admin import BaseView, expose from wtforms import DateField, Form from wtforms.validators import Required from flask.ext.admin.form import widgets from flask import request class DateRangeForm(Form): start_date = DateField('Start', validators=[Required()], format = '%d/%m/%Y', description = 'Time that the event will occur',

flask admin : sqlalchemy.exc.InterfaceError(Error binding parameter 8)

末鹿安然 提交于 2019-11-29 18:17:46
I was trying to save a project's reviewer using below, and the select field shows correct: # Query the user with Role.id == 4 as reviewer def reviewer_choices(): return User.query.join(User.roles).filter(Role.id == 4) # Build a select field class ProjectView(sqla.ModelView): form_extra_fields = { 'reviewer': sqla.fields.QuerySelectField( label='Reviewer', query_factory=reviewer_choices, )} However, when I was trying to save it, the error occurred: InterfaceError: (sqlite3.InterfaceError) Error binding parameter 8 - probably unsupported type. [SQL: u'INSERT INTO project(...reviewer...)VALUES(..