flask-admin

How can I filter a column in the edit form with Flask-Admin ModelView?

有些话、适合烂在心里 提交于 2019-12-23 01:16:14
问题 I am using a model view with flask-admin and I want to filter a column in the edit/create view. The column/field is a relationship and I only want to show fields that belong to the logged in user i.e. relationship_id == user.id 回答1: Actually I found a easier way for that as below, seems there's no need to override the edit_form method in ModelView, just pass the filtering function as a named parameter(query_factory) to the form_args, and it works like a charming!. class CustomModelView

How can I filter a column in the edit form with Flask-Admin ModelView?

老子叫甜甜 提交于 2019-12-23 01:16:07
问题 I am using a model view with flask-admin and I want to filter a column in the edit/create view. The column/field is a relationship and I only want to show fields that belong to the logged in user i.e. relationship_id == user.id 回答1: Actually I found a easier way for that as below, seems there's no need to override the edit_form method in ModelView, just pass the filtering function as a named parameter(query_factory) to the form_args, and it works like a charming!. class CustomModelView

Flask-admin, editing relationship giving me object representation of Foreign Key object

泪湿孤枕 提交于 2019-12-22 10:17:42
问题 I have a flask project, and I am getting started learning the flask-admin module. SqlAlchemy schema for the required tables. import datetime import sqlalchemy from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import backref, relationship Base = declarative_base() class Workgroup(Base): __tablename__ = 'workgroups' id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True, autoincrement=True ) name = sqlalchemy.Column(sqlalchemy.String(16)) shorthand = sqlalchemy

Make primary-key fields editable in Flask-Admin

隐身守侯 提交于 2019-12-22 10:06:52
问题 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

Batch Editing in Flask-Admin

为君一笑 提交于 2019-12-22 10:06:32
问题 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

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

牧云@^-^@ 提交于 2019-12-22 04:57:08
问题 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. 回答1: You should extend your view from ModelView and

Wrong dashboard while adding flask-admin to project

ⅰ亾dé卋堺 提交于 2019-12-21 07:33:50
问题 I'm trying to extend the flask-base project https://github.com/hack4impact/flask-base/tree/master/app. This uses the the application factory pattern in app/init.py and blueprints. In the app/init.py I have: import os from flask import Flask from flask_mail import Mail from flask_sqlalchemy import SQLAlchemy from flask_login import LoginManager from flask_assets import Environment from flask_wtf import CsrfProtect from flask_compress import Compress from flask_rq import RQ from flask_admin

Wrong dashboard while adding flask-admin to project

久未见 提交于 2019-12-21 07:33:11
问题 I'm trying to extend the flask-base project https://github.com/hack4impact/flask-base/tree/master/app. This uses the the application factory pattern in app/init.py and blueprints. In the app/init.py I have: import os from flask import Flask from flask_mail import Mail from flask_sqlalchemy import SQLAlchemy from flask_login import LoginManager from flask_assets import Environment from flask_wtf import CsrfProtect from flask_compress import Compress from flask_rq import RQ from flask_admin

Flask-Admin customize datetime view

筅森魡賤 提交于 2019-12-21 05:04:07
问题 When using flask-admin, the list view for datetime fields is something like this: "2014-02-22 13:30:43". I'd like to know if is possible to change this default view for something like this: "2014-02-22" or "2014-02-22 13:30". thanks 回答1: Yes, you can set the column_type_formatters to define default formats. Also, you can set column_formatters to use custom formats only to one column in your list view. https://flask-admin.readthedocs.org/en/latest/api/mod_model/#flask.ext.admin.model

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

倖福魔咒の 提交于 2019-12-20 03:24:06
问题 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? 回答1: 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