Mixin classes specific to Flask-Admin and Flask-SQLAlchemy based views.
Note
The following packages must be installed:
Bases: flask_velox.mixins.sqla.read.TableModelMixin
Extends the default functionality of flask_velox.mixins.sqla.model.TableModelMixin adding admin specific functionality, for example the ability to add CRUD urls so the table can render links to other views.
Example
1 2 3 4 5 6 | from yourapp.models import MyModel
class MyView(AdminTableModelMixin):
model = MyModel
with_selected = {
'Delete': 'admin.mymodel.delete',
}
|
Note
The Flask URL Rules shown above are dependant on how the admin class is registered. In this case it would be registered with an endpoint key word argument, for example:
MyView(
name='My Model',
url='mymodel',
endpoint='admin.mymodel')
Flask url rule for linkinging to create views for the model, defaults to .create
Flask url rule for linkinging to update views for the model, defaults to .update
Flask url rule for linkinging to delete views for the model, defaults to .delete
Dictionary containg a human name as the key and a Flask url rule as the value. In the example below Delete is the name which will appear in the With Selected with the url being the destination of the link.
Returns the url to a create endpoint, this is used to render a link in admin table views with the destination of this url, should be added to view context and called in the template:
<a href="{{ create_url() }}">Create New</a>
The create_url_rule must be defined otherwise None will be returned.
Parameters: | **kwargs – Arbitrary keyword arguments passed to Flask.url_for |
---|---|
Returns: | Generated url or None |
Return type: | str or None |
Returns the url for deleting a specific record, this method needs to be passed to the context of the view so it can be used in the template, for example:
{% for object in objects %}
<a href="{{ delete_url(id=object.id) }}">Delete</a>
{% endfor %}
If delete_url_rule is not defined None will be returned.
Parameters: | **kwargs – Arbitrary keyword arguments passed to Flask.url_for |
---|---|
Returns: | Generated url or None |
Return type: | str or None |
Returns the create_url_rule or None if not defined.
Returns: | Defined create_url_rule or None |
---|---|
Return type: | str or None |
Returns the delete_url_rule or None if not defined.
Returns: | Defined delete_url_rule or None |
---|---|
Return type: | str or None |
Returns the update_url_rule or None if not defined.
Returns: | Defined update_url_rule or None |
---|---|
Return type: | str or None |
Just returns the value of with_selected or None of not defined.
Returns: | Values of with_selcted |
---|---|
Return type: | dict or None |
Adds extra context to Admin Table Views for Flask-Admin systems
See also
Note
Adds the following context variables.
Returns the url for updating a specific record, this method needs to be passed to the context of the view so it can be used in the template, for example:
{% for object in objects %}
<a href="{{ update_url(id=object.id) }}">Update</a>
{% endfor %}
If update_url_rule is not defined None will be returned.
Parameters: | **kwargs – Arbitrary keyword arguments passed to Flask.url_for |
---|---|
Returns: | Generated url or None |
Return type: | str or None |