flask-admin

How do I properly set up flask-admin views with using an application factory?

夙愿已清 提交于 2019-12-06 10:25:56
问题 I'm trying to setup flask-admin model views with SQLAlchemy against 'user' and 'role' models. Instead of a function admin view I'm getting: ValueError: Invalid model property name <class 'app.models.Role'>.desc Stack trace: Traceback (most recent call last): File "/Users/dbg/Projects/Python/Current/ziff/flaskbase/manage.py", line 18, in <module> app = create_app(os.getenv('APP_CONFIG') or 'default') File "/Users/dbg/Projects/Python/Current/ziff/flaskbase/app/__init__.py", line 49, in create

Custom list view with Flask-Admin

Deadly 提交于 2019-12-06 05:27:52
问题 I have a simple model Call and I'm using Flask-Admin to create/edit/delete instances of this model. One of the field of Call is the path to an audio file. I would like to be able to play the file in the admin by adding some html code. I checked the template flask_admin/templates/bootstrap3/admin/model/list.html and it seems that the only way to do what I want is to add a cell at the end of the row, which means extending list.html, copying the whole block list_row and adding my cell. Is it the

Flask-Admin Role Based Access - Modify access based on role

孤街浪徒 提交于 2019-12-06 02:06:29
问题 I took the Flask-Admin auth example from here and changed it slightly. I added the following block to the view below, but it doesn't show the export button. I was expecting it to add the export option to the admin views. It does print ---superuser to the console. if current_user.has_role('superuser'): can_export = True print ' ---- superuser ' I have used the export feature many times before. It will work if I put the statement can_export = True just below class MyModelView(sqla.ModelView): I

Batch Editing in Flask-Admin

拟墨画扇 提交于 2019-12-06 01:35:41
I'm using Flask-Admin and I want to be able to update many fields at once from the list view. It seemed like what I'm looking for is a custom action. I was able to make it work, but I suspect not in the best way. I'm wondering if it could be done more "Flask"-ily. What I do now, for example if I was updating all rows in table cars to have tires = 4 : A custom action in the CarView class collects the ids of the rows to be modified, a callback url from request.referrer , and the tablename cars , and returns render_template(mass_update_info.html) with these as parameters. mass_update_info.html is

Select2 field implementation in flask/flask-admin

谁说我不能喝 提交于 2019-12-05 23:48:03
问题 I'm trying to implement Select2 field in one of my flask views. Basically I want the same select2 field in my flask application view (not a flask admin modelview) as in Flask-admin model create views. Currently my solution has been QuerySelectField from wtforms that looks something like this class TestForm(Form): name= QuerySelectField(query_factory=lambda: models.User.query.all()) This allows me to load and select all the data I need, but it does not provide select2 search box etc. Currently

Make primary-key fields editable in Flask-Admin

孤人 提交于 2019-12-05 20:57:09
I am using Flask-Admin for my Flask-based project. In it, I have some models (using peewee) where the primary-key is user-set, such as username for a User . However Flask-Admin is not showing these fields in the model's create/edit pages. Now, when I try to create a new user, the "Save" button gives a peewee.UserDoesNotExist error, and the "Save & Add" says "Record successfully created" twice but doesn't actually do anything. I had extended the save() method to auto-generate the username from the name if it's unset, but the problem persisted even when I removed the overriding. The code... Here

Flask Admin ModelView different fields between CREATE and EDIT

≡放荡痞女 提交于 2019-12-05 10:21:13
In a Flask app using Flask Admin I would like to be able to define different form fields in the Edit section of a ModelView than those in the Create section. The form_columns setting applies to both Create and Edit, but I can't seem to find a way to give different sets of columns to each section. You can use form_edit_rules and form_create_rules to override form columns/fields. 来源: https://stackoverflow.com/questions/31797671/flask-admin-modelview-different-fields-between-create-and-edit

How to make a field non-editable in Flask Admin view of a model class

帅比萌擦擦* 提交于 2019-12-05 05:39:13
I have a User model class and password is one attribute among many. I am using Flask web framework and Flask-Admin extension to create the admin view of my model classes. I want to make certain fields in the admin view like password non editable or not show them at all. How do I do it? I can make the fields not show up in the normal view but when I click on the edit button of any record in the table, all fields show up and are editable. You should extend your view from ModelView and overwrite the necessary fields. In my class it looks like this: class UserView(ModelView): column_list = ('first

How can I avoid Flask-Admin 2.1 warning “UserWarning: Fields missing from ruleset”?

可紊 提交于 2019-12-04 21:56:44
问题 I'm using Flask-Admin 2.1 with Python 2.7.6. One of my Flask-Admin model classes inherits from flask.ext.admin.contrib.sqla.ModelView and overrides form_rules . When I run my application, this warning is displayed: "UserWarning: Fields missing from ruleset" The warning is accurate: There are fields in my model that are not included in the ruleset. But that's by design. I don't want those fields to be displayed when users create or edit instances of this model. I have already read this: https:

Passing Arguments to ModelView edit template in flask-admin

我只是一个虾纸丫 提交于 2019-12-04 17:40:46
问题 I am trying to learn more about Flask by building a CMS. I am using flask-admin to add the posts, images etc. I have managed to override textarea with ckeditor. But I want to pass the paths of the images in the static folder to ckeditor image plugin. I can't figure out how to pass parameters to my edit.html template. Here's the code: class TestAdmin(ModelView): form_overrides = dict(text=forms.CustomTextAreaField) create_template = 'edit.html' edit_template = 'edit.html' From the