flask-admin

on_form_prefill delete all fields values if it executes form.process

你。 提交于 2019-12-08 04:28:21
问题 I want to override the form of the Matriline model shown below. First I add an extra field clan , and in on_form_prefill I reset this field's choices and default (just testing). Without calling form.process the choices are set to my new options, but the default option is not selected. If calling form.process the choices are set to my new options and the default option is selected, but all the other fields are deleted. Anybody can help? views.py class MatrilineAdmin(sqla.ModelView): form_extra

Dynamic SelectField validation fails with: “Not a valid choice”

人走茶凉 提交于 2019-12-08 04:11:20
问题 Here's my code, i can't get past the "not a valid choice" on the SelectField, being it in the creation form or the editing one... The categories i'm passing it as choices are unicode, even so i tried various "coerce" settings in the Form SelectField class ProductsView(MyModelView): create_template = '/admin/edit-products.html' form = ProductForm def create_form(self, model=None): form = self.form() choices = list(db.db.categories.find()) choices.sort(key=lambda x: x['order']) sorted_choices =

Access model's attrubutes inside of ModelView class

蹲街弑〆低调 提交于 2019-12-08 01:01:43
问题 Sorry in advance if it's a stupid question, but I am still a bit confused. Reading the flask admin documentation hasn't given any result yet. In this example flask admin image upload example there is a custom ModelView called ImageView: class ImageView(sqla.ModelView): def _list_thumbnail(view, context, model, name): if not model.path: return '' return Markup('<img src="%s">' % url_for('static', filename=form.thumbgen_filename(model.path))) column_formatters = { 'path': _list_thumbnail } #

Flask-SQLAlchemy set relationship default value

青春壹個敷衍的年華 提交于 2019-12-07 21:35:56
问题 I have an app making by Flask and for database management I using Flask-admin and Flask-SQLAlchemy. And in my app there has three role, which is: admin , school parent here is the snipet of code on my table: roles_users = db.Table( 'roles_users', db.Column('user_id', db.Integer(), db.ForeignKey('user.id')), db.Column('role_id', db.Integer(), db.ForeignKey('role.id')) ) class Role(db.Model, RoleMixin): id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(80), unique=True)

Flask-admin - how to change formatting of columns - get URLs to display

和自甴很熟 提交于 2019-12-07 07:32:40
问题 Question on flask-admin. I setup flask-admin and one of the models i created is pulling urls and url titles from a mysql database. Using flask-admin, how to i get flask-admin to render the urls instead of just text? So make it easier for users to just click on the link from the flask-admin app. Thank you. I found something on the flask-admin site called column formatters, but not sure how to implement. Does anyone have an example they can share? Thanks. 回答1: Assuming you have a view named

Flask Admin ModelView different fields between CREATE and EDIT

感情迁移 提交于 2019-12-07 04:08:18
问题 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. 回答1: 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

Getting CKEditor to work with Flask Admin

岁酱吖の 提交于 2019-12-07 03:44:28
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 import Flask from flask.ext.sqlalchemy import SQLAlchemy from flask.ext.login import LoginManager from

Flask-Admin batch action with form

ε祈祈猫儿з 提交于 2019-12-07 00:23:26
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? The way I achieve this is to do an internal POST in the @action method. class AddressView(AdminView): # ... .... @action('merge', 'Merge', 'Are you sure you want to merge selected addresses?') def action_merge(self, ids):

Flask-Admin: How to change model using on_model_change?

空扰寡人 提交于 2019-12-06 12:47:24
I'm trying to set a field's value to be based on another field in the same form: def on_model_change(form, model, is_created): model.textcolumn.data = model.textcolumn2.data Updating via the Flask-Admin interface raises no exceptions, but no changes were made to the value in model.textcolumn. Inspecting the "model" object, I also noticed this is not the same as the SQLAlchemy model used to generate the ModelView. How can I change model.textcolumn's value to model.textcolumn2's value? Is there a way to access the SQLAlchemy model object directly? This would be much better. I did it using the

Access model's attrubutes inside of ModelView class

坚强是说给别人听的谎言 提交于 2019-12-06 11:42:31
Sorry in advance if it's a stupid question, but I am still a bit confused. Reading the flask admin documentation hasn't given any result yet. In this example flask admin image upload example there is a custom ModelView called ImageView: class ImageView(sqla.ModelView): def _list_thumbnail(view, context, model, name): if not model.path: return '' return Markup('<img src="%s">' % url_for('static', filename=form.thumbgen_filename(model.path))) column_formatters = { 'path': _list_thumbnail } # Alternative way to contribute field is to override it completely. # In this case, Flask-Admin won't