gadventures / django-fsm-admin

Mixin and template tags to integrate django-fsm transitions into the django admin.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compatible with other django 3rd party apps

achillis2 opened this issue · comments

It seems the current version is not compatible with other django apps, such as Django-guardian. Only the first mixin will show up in the admin page. If I put the django-fsm-admin in front of django-guardian mixin, then only django-fsm-admin buttons will show. How can I use both packages on the admin page?

For example, this code will show django-fsm-admin buttons only.

class PIAFormAdmin(FSMTransitionMixin, GuardedModelAdmin)

This will show django-guardian buttons only

class PIAFormAdmin(GuardedModelAdmin, FSMTransitionMixin)

So the order matters. But I want to show buttons from both packages on the admin page.

This is happening because they're both trying to modify the change_form.html. What you can do is add the html that one of them is trying to add in your own change_form.html either on model level or global level then let the other one extend the change_form.html on top of yours.

For example:

Create if you don't havetemplates/admin/change_form.html with the following content (copied from the FSMTransitionMixin)'s admin:

{% extends 'admin/change_form.html' %}
{% load fsm_admin %}

{% if save_on_top %}{% block submit_buttons_top %}{% fsm_submit_row %}{% endblock %}{% endif %}

{% block submit_buttons_bottom %}{% fsm_submit_row %}{% endblock %}

{% block after_field_sets %}
    {{ block.super }}
    {% fsm_transition_hints %}
{% endblock %}

and use this version

class PIAFormAdmin(GuardedModelAdmin, FSMTransitionMixin)

This is happening because they're both trying to modify the change_form.html. What you can do is add the html that one of them is trying to add in your own change_form.html either on model level or global level then let the other one extend the change_form.html on top of yours.

For example:

Create if you don't havetemplates/admin/change_form.html with the following content (copied from the FSMTransitionMixin)'s admin:

{% extends 'admin/change_form.html' %}
{% load fsm_admin %}

{% if save_on_top %}{% block submit_buttons_top %}{% fsm_submit_row %}{% endblock %}{% endif %}

{% block submit_buttons_bottom %}{% fsm_submit_row %}{% endblock %}

{% block after_field_sets %}
    {{ block.super }}
    {% fsm_transition_hints %}
{% endblock %}

and use this version

class PIAFormAdmin(GuardedModelAdmin, FSMTransitionMixin)

This works but it's being applied to every model even ones that dont have the mixin. Leading to a "object has no attribute 'get_transition_hints'" error as a result.