flask-admin / flask-admin Goto Github PK
View Code? Open in Web Editor NEWSimple and extensible administrative interface framework for Flask
License: BSD 3-Clause "New" or "Revised" License
Simple and extensible administrative interface framework for Flask
License: BSD 3-Clause "New" or "Revised" License
I have a case where I have a parent/child entity relationship between an Invoice (parent) and LineItems (child).
class Invoice(db.Model, BaseMixin, AuditMixin):
id = Column(Integer, primary_key=True)
line_items = relationship('LineItem', backref=backref('invoice'))
....
class LineItem(db.Model, BaseMixin, AuditMixin):
id = Column(Integer, primary_key=True)
invoice_id = Column(Integer, ForeignKey('invoice.id'))
# invoice = relationship from Invoice
...
When creating new line items, I pass the invoice_id explicitly and thus would like to set the id via a hidden input instead of having it a SelectList/etc.
class LineItemView(ParentModelView):
form_overrides = dict(invoice=wtforms.HiddenField)
...
I was using 1.0.1 and had no issues, but now I get the following error:
TypeError: __init__() got an unexpected keyword argument 'allow_blank'
It appears with the new model_form_converter change, the converter explicitly adds the allow_blank
keyword argument without checking whether the overridden type supports it.
https://github.com/mrjoes/flask-admin/blob/master/flask_admin/contrib/sqlamodel/form.py
Is there a better way this should be handled?
Add support for Django-like inline related form editing
using sqlalchemy as the backend store is well done, and could flask-admin supports redis backend?
not sure whether this is a bug report or just a question.
regarding the visibility of primary keys.
working:
I have a table (Country) with automatic integer primary key and a table (Country_division) referring to it. When I insert a country_division in its table, the interface allows me to select a country. I never see the value of the primary key, but it works.
not working:
I have a table (rank) with string primary key that is manually assigned. as above, I cannot see the column in the interface, but this is now a problem, because I can't specify the key manually.
since I'm still giving form to the database, I can consider falling back to automatic integer primary keys.
When going through the Model Views part of the quickstart, I ran into multiple issues of wrong variables:
from flask.ext.sqlalchemy import db
doesn't exist (I assume it should be imported from app itself)ModelView
vs ModelBase
vs ModelBaseView
confusionUserView
vs MyView
confusionAlso, one probably shouldn't use phrase 'very easy' when talking about adding new database model handlers ;)
Apparently you can't search numeric fields. Seems unreasonable to me, so it would be really nice to be able to jump to a certain primary key.
Following this example from the docs
class MyHomeView(AdminIndexView):
@expose('/')
def index(self):
return render_template('adminhome.html')
admin = Admin(index_view=MyHomeView)
will eventually raise this error
TypeError: unbound method create_blueprint() must be called with MyHomeView instance as first argument (got Admin instance instead)
The passed in index_view
is expected to be an instance not a class. Its not clear to me if this is a typo in the docs or if this line of code
self.index_view = index_view or AdminIndexView(endpoint=endpoint, url=url)
should instantiate index_view
if its a class object.
flask-admin uses babel domains, which are not yet on the official flask-babel repo ( i think mrjoes sent a pull request 3 months ago)
as a result of that, flask-admin currently cannot be translated, unless you fork, or clone/use mr joes flask-babel fork or wait for flask-babel to pull mrjoes commits.
this dependency / issue isnt documented anywhere, and flask-admin does not complain about the them not being implemented, and instead defaults to the currently set strings.
tl;dr : why implement it that way, ( dependency on not yet pulled to official flask-babel repo ) ?
thanks.
I ran into an issue where I have an application that uses blueprints for the multiple sub-apps it serves. I wanted to make an admin page specifically for each blueprint but ran into an issue trying to create multiple Admin objects using the same app. Any suggestions?
I've looked through the source and the offending code is in the add_view function in base.py- it is registering the same view twice for the app. A simple fix would be to check if the blueprint is already registered prior to registering.
I have a SqlAlchemy model with a String field that holds a file path. I'd really like to force this to be a wtf FileField, but based on the docs / src, I don't see how this is possible. Am I missing something?
Thanks!
I'm using application factory, and as a result, using admin.init_app() method inside of create_app function. Unit tests create a new app app on each run, so that init_app gets called multiple times. The problem is that it raises on second run:
Exception: Flask-Admin is already associated with an application
Application fabrics are widely used for unittesting, and another extensions, like flask-sqlalchemy allow reinitialization with another app.
For now I hack this like this:
admin.app = None
admin.init_app(app)
Any plans to publish to PyPI? Thanks!
Hi,
First off: Many thanks for an awesome piece of software!
I've got a data model set-up in SQLAlchemy. Many of the tables use a composite primary key (orgid : Int, id : Int):
class User...:
orgid = db.Column(db.Integer, primary_key=True)
id = db.Column(db.Integer, db.Sequence('userId_seq'), primary_key=True)
Whenever i try to edit a user in this model i get a:
InvalidRequestError: Incorrect number of values in identifier to formulate primary key for query.get(); primary key columns are 'users.orgid','users.id'.
This threads back to line 501 in sqlamodel/view.py, which just returns an id.
Are composite keys supported by flask-admin?
Many thanks,
Tobias
For a project of mine, I need to select multiple items to carry out an action (in my case consolidate duplicate records).
I've started implementing a generalised format so other actions can be added by individuals (inspired by actions in Django with some implementation details cribbed from flask-peewee's admin module).
I've started with delete selected. I plan on cleaning it up for more general use but wanted to open it up to feedback before I go completely down the path.
https://github.com/beyondwords/flask-admin/commit/c7a3ba94fa425610b41df8b3fd59d6128bf7a744
Please contribute any comments on architecture.
BaseModelView
sub-class, request
, and id_list
label
specified for the drop-down listis_accessible
, can_delete
etc.None
and use a flash message to return to the list__call__
implementedAdd formatters support (pass callable that will be used to format table data).
If flask-admin is mounted to a top-level URL, links to static resources are broken.
Instead of setting can_edit as a class-level variable (can_edit = True
), I attempted to set it as a property so I can check the current_user (from Flask-Login) like so:
@property
def can_edit(self):
if current_user.is_admin():
return True
...
But I get the following error:
Traceback (most recent call last):
File "c:\dev\expense-assist\packages\flask_failsafe.py", line 26, in wrapper
return func(*args, **kwargs)
File "c:\dev\expense-assist\application\__init__.py", line 21, in create_app
configure_extensions(app)
File "c:\dev\expense-assist\application\extensions.py", line 56, in configure_extensions
manage.add_view(views.SupplierModelView(models.Supplier, db.session, name='Manage', category='Suppliers', endpoint='supplier'))
File "c:\dev\expense-assist\packages\flask_admin\contrib\sqlamodel\view.py", line 191, in __init__
super(ModelView, self).__init__(model, name, category, endpoint, url)
File "c:\dev\expense-assist\packages\flask_admin\model\base.py", line 252, in __init__
self.init_actions()
File "c:\dev\expense-assist\packages\flask_admin\actions.py", line 53, in init_actions
attr = getattr(self, p)
File "c:\dev\expense-assist\application\admin\base.py", line 72, in can_delete
return self.can_edit
File "c:\dev\expense-assist\application\admin\base.py", line 46, in can_edit
if current_user.is_admin():
File "c:\dev\expense-assist\packages\werkzeug\local.py", line 336, in __getattr__
return getattr(self._get_current_object(), name)
File "c:\dev\expense-assist\packages\werkzeug\local.py", line 295, in _get_current_object
return self.__local()
File "c:\dev\expense-assist\packages\flask_login.py", line 403, in <lambda>
current_user = LocalProxy(lambda: _request_ctx_stack.top.user)
AttributeError: 'NoneType' object has no attribute 'user'
It appears the code to find actions calling the can_edit property at startup and not during a request, which current_user needs -
https://github.com/mrjoes/flask-admin/blob/master/flask_admin/actions.py#L53
Currently I’m having to rewrite ModelView.scaffold_form
in a subclass to add more converters for sqlamodel. I’m not sure what the best place to specify project specific converters would be. Any thoughts?
Running the "simple.py"-SqlAlchemy-example ends up in a TypeError
when clicking "Create" on any model.
TypeError: html_params() keywords must be strings
Traceback (most recent call last):
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask/app.py", line 1701, in call
return self.wsgi_app(environ, start_response)
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask/app.py", line 1689, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask/app.py", line 1687, in wsgi_app
response = self.full_dispatch_request()
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask/app.py", line 1360, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask/app.py", line 1358, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask/app.py", line 1344, in dispatch_request
return self.view_functionsrule.endpoint
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask_admin/base.py", line 36, in inner
return f(self, *_kwargs)
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask_admin/base.py", line 36, in inner
return f(self, *_kwargs)
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask_admin/base.py", line 36, in inner
return f(self, *_kwargs)
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask_admin/model/base.py", line 803, in create_view
return_url=return_url)
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask_admin/base.py", line 177, in render
return render_template(template, *_kwargs)
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask/templating.py", line 125, in render_template
context, ctx.app)
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask/templating.py", line 107, in _render
rv = template.render(context)
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/jinja2/environment.py", line 894, in render
return self.environment.handle_exception(exc_info, True)
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask_admin/templates/admin/model/create.html", line 2, in top-level template code
{% import 'admin/lib.html' as lib with context %}
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask_admin/templates/admin/master.html", line 19, in top-level template code
{% block page_body %}
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask_admin/templates/admin/master.html", line 69, in block "page_body"
{% block body %}{% endblock %}
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask_admin/templates/admin/model/create.html", line 23, in block "body"
{% call lib.form_tag() %}
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask_admin/templates/admin/lib.html", line 109, in template
{{ caller() }}
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask_admin/templates/admin/model/create.html", line 24, in template
{{ lib.render_form_fields(form) }}
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask_admin/templates/admin/lib.html", line 77, in template
{{ form.hidden_tag() if form.hidden_tag is defined }}
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask_wtf/form.py", line 113, in hidden_tag
rv.append(unicode(field))
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/wtforms/fields/core.py", line 116, in unicode
return self()
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/wtforms/fields/core.py", line 139, in call
return self.widget(self, *_kwargs)
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/wtforms/widgets/core.py", line 124, in call
return HTMLString('<input %s>' % self.html_params(name=field.name, *_kwargs))
TypeError: html_params() keywords must be strings
Installed Libraries (all installed with PIP):
Flask==0.9
Flask-Admin==1.0.2
Flask-SQLAlchemy==0.16
Flask-WTF==0.8
Jinja2==2.6
SQLAlchemy==0.7.8
WTForms==1.0.2
Werkzeug==0.8.3
flask-csrf==0.9.2
wsgiref==0.1.2
I have a model with a string ID as primary key. When I create a model-based view, I see this error:
ValueError: invalid literal for int() with base 10: 'WC'
which is coming from here in list.html:
Are non Integer primary keys not supported?
Currently, forms don't support default column values and display wrong data.
There are some situations when one need do some actions after (or better during creation/saving of a new model).
For example, I need to generate a list of allowed endpoints for fresh or changed Role object.
With current behavior I have to copy the whole method code from the base class:
def update_model(self, form, model):
try:
form.populate_obj(model)
self.session.flush()
self.update_role_allowed_endpoints(form, model) # <------
self.session.commit()
return True
except Exception, ex:
flash(gettext('Failed to update model. %(error)s', error=str(ex)), 'error')
return False
def create_model(self, form):
# Copypasted from base class to be able to modify model instance after creation
try:
model = self.model()
form.populate_obj(model)
self.session.add(model)
self.session.flush()
self.update_role_allowed_endpoints(form, model) # <-------
self.session.commit()
return True
except Exception, ex:
flash(gettext('Failed to create model. %(error)s', error=str(ex)), 'error')
return False
Take note, changes take place in the middle of transaction, so any exceptions in my method do not break data consistency.
I propose to add 'model_changed' class attribute (a callable which takes a form and a model). And call it before transaction commit.
Duplicate found https://github.com/mrjoes/flask-admin/pull/61.
-- REMOVE ME --
I'm getting this error when using sqlalchemy ModelView and pressing create. Is there an easy way to just disable csrf?
class Test(db.Model):
value = db.Column(db.Float, default=0.0, nullable=True)
when i use this with flask-admin as following:
admin.add_view(sqlamodel.ModelView(Test, db.session))
when i create a Test, it raise:
File "E:\bin\Python27\lib\site-packages\wtforms\fields\core.py", line 539, in _value
return format % self.data
TypeError: a float is required
here, type(self.data) is class 'sqlalchemy.schema.ColumnDefault'
and format is "%0.2f"
Simple but annoying
HI,
I use sqlamodel, and I found the form's field of db.Column(db.Integer, default = 0) default value is not 0, but is
ColumnDefault(0)
When I attempt to create a new object, I get TypeError: macro 'render_form' takes not more than 2 argument(s)
.
Code implementing Flask-AdminEx: http://pastebin.com/bWr0K7Le
Traceback: http://pastebin.com/GpMBV9iV
Running Flask-AdminEx 0.0.1 8679ea3 on Python 2.7.2 on virtualenv 1.7 on OS X Snow Leopard 10.6.8.
Installed packages:
Flask-AdminEx==0.0.1
Flask-Bcrypt==0.5.2
Flask-SQLAlchemy==0.15
Flask-WTF==0.6
Jinja2==2.6
SQLAlchemy==0.7.5
WTForms==1.0.1
Werkzeug==0.8.3
py-bcrypt==0.2
wsgiref==0.1.2
When trying to use sqla's simple.py example bundled with flask-adminex, I get an error when displaying a ModelView with a non-empty model.
The error is UndefinedError: 'get_pk_value' is undefined
Process:
From here you can:
Because user is correctly added to the sqlite base, I think this is a typo or something.
Ismael.
Regression in cade92d
Issue can be fixed by
diff --git flask_admin/model/base.py flask_admin/model/base.py
index 91ea697..8368899 100644
--- flask_admin/model/base.py
+++ flask_admin/model/base.py
@@ -806,7 +806,7 @@ class BaseModelView(BaseView, ActionsMixin):
return self.render(self.create_template,
form=form,
- return_url=return_url)
+ cancel_url=return_url)
@expose('/edit/', methods=('GET', 'POST'))
def edit_view(self):
@@ -835,7 +835,7 @@ class BaseModelView(BaseView, ActionsMixin):
return self.render(self.edit_template,
form=form,
- return_url=return_url)
+ cancel_url=return_url)
@expose('/delete/', methods=('POST',))
def delete_view(self):
OR
diff --git flask_admin/templates/admin/model/create.html flask_admin/templates/admin/model/create.html
index be1a044..d07afc9 100644
--- flask_admin/templates/admin/model/create.html
+++ flask_admin/templates/admin/model/create.html
@@ -22,7 +22,7 @@
{% call lib.form_tag() %}
{{ lib.render_form_fields(form) }}
- {{ lib.render_form_buttons(cancel_url, extra()) }}
+ {{ lib.render_form_buttons(return_url, extra()) }}
{% endcall %}
{% endblock %}
diff --git flask_admin/templates/admin/model/edit.html flask_admin/templates/admin/model/edit.html
index ea03875..74dabc7 100644
--- flask_admin/templates/admin/model/edit.html
+++ flask_admin/templates/admin/model/edit.html
@@ -9,7 +9,7 @@
{% block body %}
{% call lib.form_tag() %}
{{ lib.render_form_fields(form) }}
- {{ lib.render_form_buttons(cancel_url) }}
+ {{ lib.render_form_buttons(return_url) }}
{% endcall %}
{% endblock %}
When I attempt to run from flask.ext.adminex.ext.sqlamodel import ModelView
, I get the following:
Traceback (most recent call last):
File "run.py", line 19, in <module>
from metacraft.views.admin import adminex
File "/Users/natan/Development/metacraft/metacraft/views/admin.py", line 5, in <module>
from flask.ext.adminex.ext.sqlamodel import ModelView
File "/Users/natan/.virtualenvs/metacraft/lib/python2.7/site-packages/Flask_AdminEx-0.0.1-py2.7.egg/flask_adminex/ext/sqlamodel/__init__.py", line 1, in <module>
from .view import ModelView
File "/Users/natan/.virtualenvs/metacraft/lib/python2.7/site-packages/Flask_AdminEx-0.0.1-py2.7.egg/flask_adminex/ext/sqlamodel/view.py", line 14, in <module>
from flask.ext.adminex.model import BaseModelView
File "/Users/natan/.virtualenvs/metacraft/lib/python2.7/site-packages/flask/exthook.py", line 86, in load_module
raise ImportError('No module named %s' % fullname)
ImportError: No module named flask.ext.adminex.model
Running Python 2.7.2 with virtualenv 1.7 on OS X Snow Leopard 10.6.8 with the following packages:
Flask-AdminEx==0.0.1
Flask-Bcrypt==0.5.2
Flask-SQLAlchemy==0.15
Flask-WTF==0.6
Jinja2==2.6
SQLAlchemy==0.7.5
WTForms==1.0.1
Werkzeug==0.8.3
py-bcrypt==0.2
wsgiref==0.1.2```
using sqlalchemy as the backend store is well done, and could flask-admin support redis backend?
ENUM columns (supported by at least SQLAlchemy/Postgres) are currently represented as simple text input fields.
It seems that checking column types doesn't really work (currently column.type
returns VARCHAR(...)
), so a way to define user-defined editors would be needed as a workaround.
Not sure whether it's a feature or bug, but sqla's ModelView doesn't seem to be showing related child objects (one-to-many) by default. This also means that I need to rewrite the whole column list via list_columns
.
It would be nice if the tarball releases are tagged in the repository.
Using the initial example in the tutorial works. But if I do any configuration of the application, the admin UI will 404. E.g.
from flask import Flask
from flask.ext.admin import Admin
app = Flask(__name__)
app.config.from_pyfile('testapp.cfg')
admin = Admin(app)
app.run()
If I navigate to http://localhost:5000/admin/
, I get a 404. Comment out the app.config ...
line and it works fine. Doesn't matter what I put in the config file
I'm using Flask 0.9 and Flask-Admin 1.0.1
I have a situation where I've added a column filter to a view and would like to manually apply it in a request. For example, with the following view:
class LineItemView(ModelView):
column_filters = [FilterEqual(models.LineItem.invoice_id, "parent")]
to apply the filter via url, I need to use something like /admin/lineitem/?flt0_0={{request.args["id"]}}
, which is confusing, and reliant on knowing the index position of the filters you want to apply.
Since this is an instance filter with a name ("parent") and a specific filter (FilterEqual) instead of a genearl column name (ex. ['foo']), it would be nice if you could apply the filter like this:
/admin/lineitem/?flt_admin={{request.args["id"]}}
For the cases where just a field name is used, maybe something like:
/admin/lineitem/?flt_admin_eq={{request.args["id"]}}
/admin/lineitem/?flt_admin_ne={{request.args["id"]}}
/admin/lineitem/?flt_admin_gt={{request.args["id"]}}
/admin/lineitem/?flt_admin_lt={{request.args["id"]}}
Thoughts?
New version WTForms (1.0.2) makes Flask-admin crashed with error:
File "/home/klen/Projects/tweetchi/base/core/admin.py", line 10, in <module>
admin.add_model(Alembic, AlembicView)
File "/home/klen/Projects/tweetchi/base/core/ext.py", line 38, in add_model
self.add_view(view(model, db.session))
File "/home/klen/Projects/tweetchi/.env/local/lib/python2.7/site-packages/flask_admin/contrib/sqlamodel/view.py", line 141, in __init__
super(ModelView, self).__init__(model, name, category, endpoint, url)
File "/home/klen/Projects/tweetchi/.env/local/lib/python2.7/site-packages/flask_admin/model/base.py", line 222, in __init__
self._refresh_cache()
File "/home/klen/Projects/tweetchi/.env/local/lib/python2.7/site-packages/flask_admin/model/base.py", line 234, in _refresh_cache
self._create_form_class = self.get_create_form()
File "/home/klen/Projects/tweetchi/.env/local/lib/python2.7/site-packages/flask_admin/model/base.py", line 419, in get_create_form
return self.get_form()
File "/home/klen/Projects/tweetchi/.env/local/lib/python2.7/site-packages/flask_admin/model/base.py", line 411, in get_form
return self.scaffold_form()
File "/home/klen/Projects/tweetchi/.env/local/lib/python2.7/site-packages/flask_admin/contrib/sqlamodel/view.py", line 367, in scaffold_form
converter=form.AdminModelConverter(self))
File "/home/klen/Projects/tweetchi/.env/local/lib/python2.7/site-packages/wtforms/ext/sqlalchemy/orm.py", line 303, in model_form
converter)
File "/home/klen/Projects/tweetchi/.env/local/lib/python2.7/site-packages/wtforms/ext/sqlalchemy/orm.py", line 241, in model_fields
field_args.get(name), db_session)
TypeError: convert() takes exactly 5 arguments (6 given)
With WTForms==1.0.1 it works as fine.
Verify how wtf generates field for m2m.
Hi, I tried using flask-admin for a many-to-many relationship defined in SQLAlchemy like so: http://docs.sqlalchemy.org/en/rel_0_7/orm/tutorial.html#building-a-many-to-many-relationship
The UI works great, however because the fields are designated as "required", on a blank database I am not able to use the UI to add any rows to the database. The forms to add rows in both tables will give an error "This field is required.", and the select box is empty because the other table is still empty. What should I do?
Going through the examples and trying to use some of my apps into it. I was wondering if we could actually make list_columns, rename_columns, etc. more into options instead of customization?
For example, I want to be able to use the normal sqlalchemy interface, but according to the documentation I would need to create a custom interface in order to utilize the list_columns functionality. I would not be able to use the sqlalchemy interface.
As a workaround I made it so that I could pass those customization when I first create the View. Would this be the best way to do it? Or should we come up with some sort of API to do such a thing?
WYSIWYG HTML-editor and file manager based jQueryUI.
Required to change displayed data in the list view.
When setting up FileAdmin to point at invalid directory that doesn't exist, it simply errors out with 404 and shows default site error page.
I'm unable to use the sqlamodel extension due to an import error. Please see below. Perhaps a packaging problem?
from flask.ext.adminex.ext.sqlamodel import ModelBase
File "/Users/andy/.virtualenvs/marty/lib/python2.7/site-packages/flask/exthook.py", line 86, in load_module
raise ImportError('No module named %s' % fullname)
ImportError: No module named flask.ext.adminex.ext
for example, if I have model as following:
class T(db.Model):
a = db.column()
b = db.column()
c = db.column()
d = db.column()
e = db.column()
In admin, when i create, i only want the create form show a and b, how to do it?
Thanks.
Instead of setting can_edit as a class-level variable (can_edit = True
), I attempted to set it as a property so I can check the current_user (from Flask-Login) like so:
@property
def can_edit(self):
if current_user.is_admin():
return True
...
But I get the following error:
Traceback (most recent call last):
File "c:\dev\expense-assist\packages\flask_failsafe.py", line 26, in wrapper
return func(*args, **kwargs)
File "c:\dev\expense-assist\application\__init__.py", line 21, in create_app
configure_extensions(app)
File "c:\dev\expense-assist\application\extensions.py", line 56, in configure_extensions
manage.add_view(views.SupplierModelView(models.Supplier, db.session, name='Manage', category='Suppliers', endpoint='supplier'))
File "c:\dev\expense-assist\packages\flask_admin\contrib\sqlamodel\view.py", line 191, in __init__
super(ModelView, self).__init__(model, name, category, endpoint, url)
File "c:\dev\expense-assist\packages\flask_admin\model\base.py", line 252, in __init__
self.init_actions()
File "c:\dev\expense-assist\packages\flask_admin\actions.py", line 53, in init_actions
attr = getattr(self, p)
File "c:\dev\expense-assist\application\admin\base.py", line 72, in can_delete
return self.can_edit
File "c:\dev\expense-assist\application\admin\base.py", line 46, in can_edit
if current_user.is_admin():
File "c:\dev\expense-assist\packages\werkzeug\local.py", line 336, in __getattr__
return getattr(self._get_current_object(), name)
File "c:\dev\expense-assist\packages\werkzeug\local.py", line 295, in _get_current_object
return self.__local()
File "c:\dev\expense-assist\packages\flask_login.py", line 403, in <lambda>
current_user = LocalProxy(lambda: _request_ctx_stack.top.user)
AttributeError: 'NoneType' object has no attribute 'user'
It appears the code to find actions calling the can_edit property at startup and not during a request, which current_user needs -
https://github.com/mrjoes/flask-admin/blob/master/flask_admin/actions.py#L53
I have a SqlAlchemy model with a String field that holds a file path. I'd really like to force this to be a wtf FileField, but based on the docs / src, I don't see how this is possible. Am I missing something?
Thanks!
I'm new to Flask so be patient reading and explicit writing!
how do I link the admin pages to the root of the normal Flask interface?
can I have this link in the name of the app?
I tried
admin = Admin(app, name='<a href="/">ghini</a>')
and not surprisingly, it did not work.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.