Skip to main content

django-fsm transition integration to django admin.

Project description

django-fsm-admin2

Django-fsm transition integration to django admin.

Passing arguments to transition is supported (unlike django-fsm-admin package).

Installation

pip install django-fsm-admin2

Add fsm_admin to your settings.INSTALLED_APPS

INSTALLED_APPS = [
    ...
    'fsm_admin2',
    ...
]

Usage

Add FSMTransitionMixin to your admin class

# admin.py

from django.contrib import admin
from fsm_admin2.admin import FSMTransitionMixin

class MyModelAdmin(FSMTransitionMixin, admin.ModelAdmin):
    fsm_fields = ['status',]    # list your fsm fields
    
    # you can override templates for transition arguments form view and transition buttons row
    fsm_transition_form_template = 'fsm_admin2/fsm_transition_form.html'         # default value
    fsm_transition_buttons_template = 'fsm_admin2/fsm_transition_buttons.html'   # default value
    ...
    

This will add current field value as readonly field and buttons row to perform transitions. Only allowed transitions are displayed.

Customize transition display.

@transition(field=status, source='disabled', target='enabled',
            custom={'short_description': 'Activate!!!'})
def activate(self):
    ...

Add form to provide transition arguments. Form fields names should match transition function arguments.

class DeactivateForm(forms.Form):
    text = forms.Charfield()

@transition(field=status, source='enabled', target='disabled',
            custom={'short_description': 'Deactivate', 'form': DeactivateForm})
def deactivate(self, text):
    ...

Form class can also be set as import string: {'form': 'my_app.forms.DeactivateForm'}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-fsm-admin2-0.1.3.tar.gz (5.1 kB view hashes)

Uploaded Source

Built Distribution

django_fsm_admin2-0.1.3-py3-none-any.whl (5.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page