flask-admin

how to use flask-admin for editing modelview

和自甴很熟 提交于 2019-11-29 15:21:04
问题 How to set password_hash using generate_password_hash from the edit page of flask-admin i create a username and password in python shell. the password is hashing admin.add_view(MyModelView(User, db.session) - let me edit the User class Models when i edit the password and submit but the password is saved in plain text. How to edit password from flask-admin, the password should be save in hashing type My code is: from werkzeug.security import generate_password_hash, check_password_hash class

Readonly text field in Flask-Admin ModelView

我的未来我决定 提交于 2019-11-29 09:34:48
How can I make a field on a ModelView readonly? class MyModelView(BaseModelView): column_list = ('name', 'last_name', 'email') Richard Aplin If you're talking about Flask-Admin with SQLAlchemy Models, and you're declaring a view by inheriting from sqlamodel.ModelView, you can just add this to your class definition: class MyModelView(BaseModelView): column_list = ('name', 'last_name', 'email') form_widget_args = { 'email':{ 'disabled':True } } I don't have enough reputation to comment on @thkang's answer, which is very close to what worked for me. The disabled attribute excludes the field from

Customize (override) Flask-Admin's Submit method from edit view

♀尐吖头ヾ 提交于 2019-11-29 03:55:47
Preconditions: I'm new to Python and to Flask-Admin in particular. I created a simple test service, which has MondoDB, keeping the data with relationship of 'one-to-one' kind. employeeName -> salary The model looks like that: class Employee(db.Document): fullName = db.StringField(max_length=160, unique=True) salary = db.IntField() And I use Flask-Admin to observe the table with the data and to edit it. When I want to change the 'salary' field, I just press the 'edit' button and in Flask-Admin's default edit view I change the integer value. I press 'Submit' and a new value in the database is

DatePickerWidget with Flask, Flask-Admin and WTforms

邮差的信 提交于 2019-11-28 17:54:25
问题 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

How to tell flask-admin to use alternative representation when displaying Foreign Key Fields?

社会主义新天地 提交于 2019-11-28 10:25:37
问题 How can I tell flask-admin to use an alternative representation for Foreign Key Fields such as the following in this RoleUser link table? 回答1: The simplest way is to add __str__ methods ( __unicode__ for Python 2) to your models. class Role(db.Model): # snip def __str__(self): return self.name 来源: https://stackoverflow.com/questions/34702734/how-to-tell-flask-admin-to-use-alternative-representation-when-displaying-foreig

flask-admin form: Constrain Value of Field 2 depending on Value of Field 1

拥有回忆 提交于 2019-11-28 08:35:01
One feature I have been struggling to implement in flask-admin is when the user edits a form, to constrain the value of Field 2 once Field 1 has been set. Let me give a simplified example in words (the actual use case is more convoluted). Then I will show a full gist that implements that example, minus the "constrain" feature. Let's say we have a database that tracks some software "recipes" to output reports in various formats. The recipe table of our sample database has two recipes: "Serious Report", "ASCII Art". To implement each recipe, we choose one among several methods. The method table

How to run Airflow on Windows

亡梦爱人 提交于 2019-11-28 07:24:24
The usual instructions for running Airflow do not apply on a Windows environment: # airflow needs a home, ~/airflow is the default, # but you can lay foundation somewhere else if you prefer # (optional) export AIRFLOW_HOME=~/airflow # install from pypi using pip pip install airflow # initialize the database airflow initdb # start the web server, default port is 8080 airflow webserver -p 8080 The Airflow utility is not available in the command line and I can't find it elsewhere to be manually added. How can Airflow run on Windows? You can activate bash in windows and follow the tutorial as is.

Flask-Admin default filters

被刻印的时光 ゝ 提交于 2019-11-28 06:57:06
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 Order.query.filter(Order.paid==True) query. Is it

Readonly text field in Flask-Admin ModelView

风流意气都作罢 提交于 2019-11-28 02:58:12
问题 How can I make a field on a ModelView readonly? class MyModelView(BaseModelView): column_list = ('name', 'last_name', 'email') 回答1: If you're talking about Flask-Admin with SQLAlchemy Models, and you're declaring a view by inheriting from sqlamodel.ModelView, you can just add this to your class definition: class MyModelView(BaseModelView): column_list = ('name', 'last_name', 'email') form_widget_args = { 'email':{ 'disabled':True } } 回答2: I don't have enough reputation to comment on @thkang's

Customize (override) Flask-Admin's Submit method from edit view

纵饮孤独 提交于 2019-11-27 17:51:36
问题 Preconditions: I'm new to Python and to Flask-Admin in particular. I created a simple test service, which has MondoDB, keeping the data with relationship of 'one-to-one' kind. employeeName -> salary The model looks like that: class Employee(db.Document): fullName = db.StringField(max_length=160, unique=True) salary = db.IntField() And I use Flask-Admin to observe the table with the data and to edit it. When I want to change the 'salary' field, I just press the 'edit' button and in Flask-Admin