flask-admin

Remove duplicates from QuerySelectField

£可爱£侵袭症+ 提交于 2020-01-06 07:53:34
问题 i'm running into issues with the following, and I'm wondering if it is even possible. I have a flask-admin adminview setup, with an extra form field which shows a dropdown based on a specific column (category) in the sql model. See code for clarification: model: class Item(db.Model): id = db.Column(db.Integer, primary_key = True) name = db.Column(db.String(128), index = True) category = db.Column(db.String(16)) I have the extra form field in Flask-Admin as follows: form_extra_fields = {

Flask-Admin pages inaccessible in production

北战南征 提交于 2020-01-04 04:43:04
问题 I am trying to deploy my Flask app using Apache and mod_wsgi on an Ubuntu server. It seems to work fine for restful requests that I have implemented, but I can't access my Flask-Admin pages (which I can access in development). Here is the structure of my app (simplified for the purpose of this question) : - MyApp/ - main.py - myapp/ - __init__.py - Views.py - files/ - wsgi/ myapp.wsgi When in development, I simply run by using python main.py and everything works fine. Here is the wsgi file :

Access Control for Flask-Admin

本秂侑毒 提交于 2019-12-30 10:34:53
问题 My flask app centers around modifying models based on SQLAlchemy. Hence, I find flask-admin a great plugin because it maps my SQLA models to forms with views already defined with a customizable interface that is tried and tested. I understand that Flask-admin is intended to be a plugin for administrators managing their site's data. However, I don't see why I can't use FA as a framework for my users to CRUD their data as well. To do this, I have written the following: class

Modify input field sizes in Flask-Admin

女生的网名这么多〃 提交于 2019-12-25 03:00:32
问题 Does anyone know of an easy way to specify a size for input fields in Flask-Admin? E.g. setting class="input-xlarge" on an input field does the trick, but is there a simple way to do that from Flask-Admin? 回答1: Use form_widget_args . For example: class MyModelView(BaseModelView): form_widget_args = { 'description': { 'rows': 10, 'class': 'input-xlarge' } } 回答2: Somewhat dirty way, but still useful class MyModelView(BaseModelView): form_widget_args = { 'description': { 'rows': 20, 'style':

DateBetweenFilter filter is not working in flask admin

▼魔方 西西 提交于 2019-12-24 12:51:36
问题 I created a custom datetimefilter in flask admin and it looks good(able to select the datetime range) in the UI, but not working in functionality. I think the apply method is not working. The table which i'm going to apply this filter is in Cassandra . from flask_admin.contrib.sqla.filters import BaseSQLAFilter from flask_admin.model import filters class DateBetweenFilter(BaseSQLAFilter, filters.BaseDateBetweenFilter): def __init__(self, column, name, options=None, data_type=None): super

How to access the model instance from custom flask admin template

混江龙づ霸主 提交于 2019-12-24 01:39:57
问题 I need to create a pretty complicated view of nested models in my admin page, googled all around the globe (form_edit_rules, edit_template, on_form_prefill), but could not find a way to access the current DB object from the flask-admin edit page. How do I do this? 回答1: The current DB object is passed as the variable model . See flask_admin/model/base.py ~ line 2077: @expose('/edit/', methods=('GET', 'POST')) def edit_view(self): # code model = self.get_one(id) # more code return self.render

Use a “phrase search” in flask admin

守給你的承諾、 提交于 2019-12-24 01:14:30
问题 I am using Flask-Admin and I am very happy with it. The docs show several options that can be used to search predefined fields. I want to allow my users to use quotation marks to search, as for instance, in: "some phrase of which the order should be intact" How can I do this with Flask-Admin? 回答1: In Flask-Admin 1.3.0 you can override the _apply_search method in your admin view class. See the very simple code example below - mostly taken from the Flask-Admin sqla example app.py. Essentially,

Flask Admin doesn't show all fields

ⅰ亾dé卋堺 提交于 2019-12-23 19:30:33
问题 I have model like this: class User(db.Model): __tablename__ = 'users' __table_args__ = {'mysql_engine' : 'InnoDB', 'mysql_charset' : 'utf8'} id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(80), unique=True) email = db.Column(db.String(120), unique=True) _password = db.Column('password', db.String(80)) def __init__(self, username = None, email = None, password = None): self.username = username self.email = email self._set_password(password) def _set_password(self,

Flask-Admin batch action with form

空扰寡人 提交于 2019-12-23 04:16:15
问题 I have a Flask application with Flask-SQLAlchemy and Flask-Admin . I would like to perform a batch action, but with form. For example I would like to set a same text value to the form attributed, but this value is entered by the user. I saw documentation for batch actions, but it has example only for predefined data. Is it possible, or maybe there's some workaround for this? 回答1: The way I achieve this is to do an internal POST in the @action method. class AddressView(AdminView): # ... ....

Getting CKEditor to work with Flask Admin

放肆的年华 提交于 2019-12-23 01:40:11
问题 I'm trying to make turn the Flask Admin text box into a CKEdit box, as described here. However, when I run it and go to the existing admin fields it doesn't show any change to the text boxes, and when I run it and go to the TestAdmin field created to demonstrate I get this error: OperationalError: (OperationalError) no such table: test u'SELECT count(?) AS count_1 \nFROM test' ('*',) Along with a bunch of other traceback messages. I have changed my init script to be this: import os from flask