Eat at Joe's

I'm very pleased to announce Flask-Admin 1.0.2. This version has some new functionality as well as lots of bug fixes.

So what's new?

Peewee support

Flask-Admin now has Peewee ORM support out of the box.

It is supports all features, except of many-to-many relationships.

Peewee model list

Click here to see the sample

Actions

Action is a method which accepts multiple items (models, files, etc) and does something with them.

For example, SQLAlchemy and Peewee model backends expose default "mass delete" action.

Delete action

You can add your own actions by wrapping your method with a decorator:

from flask.ext.admin.actions import action

class MyModelAdmin(ModelAdmin):
    @action('merge', 'Merge', 'Are you sure you want to merge selected models?')
    def action_merge(self, ids):
        pass

Custom action

@action decorator accepts three parameters:

You can control which actions are available for current request by overriding is_action_allowed method:

from flask.ext.admin.actions import action

class MyModelAdmin(ModelAdmin):
    def is_action_allowed(self, name):
        if name == 'merge' and not user.superadmin:
            return False

        if name == 'delete' and not user.admin:
            return False

        return super(MyModelAdmin, self).is_action_allowed(name)

In action body you can either return None or Werkzeug response object:

from flask.ext.admin.actions import action

class MyModelAdmin(ModelAdmin):
    @action('merge', 'Merge', 'Are you sure you want to merge selected models?')
    def action_merge(self, ids):
        # Merge logic
        return redirect(url_for('.index'))

    @action('csv', 'Export to CSV')
    def action_combine(self, ids):
        # CSV export logic
        return self.render('export.csv', rows=rows)

Inline model administrative interface

Since 1.0.2 Flask-Admin supports inline child model editing a-la Django admin:

Custom action

Here's how it is done:

class UserAdmin(ModelAdmin):
    inline_models = (UserInfo,)

You can customize displayed form by either passing tuple to the inline_models with options or using InlineFormAdmin class:

class UserAdmin(ModelAdmin):
    inline_models = [(UserInfo, dict(form_columns=('name', 'test')))]

class InlineUserFormAdmin(InlineFormAdmin):
    form_columns = ('name', 'test')

class AnotherUserAdmin(ModelAdmin):
    inline_models = (InlineUserFormAdmin,)

You can use same form configuration properties (form_columns, exclude_form_columns, form_args, etc) to configure inline forms.

Where to get

As usual, on PyPI or on GitHub.

Documentation is here.

Anyway, hope you'll like it.

blog comments powered by Disqus