Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatible with other django 3rd party apps #104

Open
achillis2 opened this issue Apr 4, 2023 · 2 comments
Open

Compatible with other django 3rd party apps #104

achillis2 opened this issue Apr 4, 2023 · 2 comments

Comments

@achillis2
Copy link

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.

@sumanchapai
Copy link

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)

@pfcodes
Copy link

pfcodes commented Aug 15, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants