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
Allow custom change_list_template in admin views using mixins #1483
Allow custom change_list_template in admin views using mixins #1483
Conversation
Thanks @nikhaldi. Wondered if you could review @pokken-magic? |
I will review but I think it's probably a good idea to have at least a glance with someone who knows django admin templates better than me; I almost exclusively work with DRF so my template fu is less robust. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very promising to me, thank you a lot for doing this. Only two minor comments from me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick review!
I'm thinking this fix would be better suited to our forthcoming 3.0 release. Is it possible you could reset the base branch to be |
Makes sense, will do. Currently struggling with the mechanics of rebasing but I will figure it out and let you know when it's done. |
This allows users to customize the change list templates when using mixins provided by the library. In particular this enables adding more items to the object tools, in addition to the ones added by the admin mixins. This then makes this library compatible with other libraries that extend the object tools, such as `django-admin-sortable2` or `reversion`. Fixes django-import-export#1450
674cb8c
to
289a7d5
Compare
This is now rebased on release-3-x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this all makes sense to me.
Thanks Nik for the change, and thanks Ryan for reviewing.
Likewise I don't know too much about admin templates. Looping in @PetrDlouhy in case he has time to review - that would be much appreciated. |
@nikhaldi there is another merge from |
Looks less confusing like this in the demo app.
Thanks, should now be properly merged. |
It's not a rendering issue per se, it's just a text-only item that I inserted into the customized change list template. I need to insert something so I can write a test to verify it's working. I turned this into a real link (that goes nowhere) now, so it's maybe a bit less disjointed looking? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm concerned that the default button will be confusing for users, please see my alternative suggestion.
Should avoid confusion by users using the sample application.
@nikhaldi thanks for the PR all looks good to me. One final question - do you think there is a risk that this might affect any existing implementations that users might have? If so, it will be fine for the v3 release but we may need to add a note to changelog.rst re breaking changes. |
For some reason, the link still renders when placed in Please could you fix this? |
I would say the risk is small and it should rarely outright break something, but it can definitely affect existing implementation (e.g., it does in the real-world project I'm working on). I added a comment to the changelog but let me know if this is overkill. |
Strange. You can see in the screenshot I posted previously that the list item is in the HTML source but is not rendered in my browser, but it may well be a browser-specific issue. I changed this to a HTML comment now, that will definitely not render and does the job. |
Problem
The mixins for the admin integration override the admin
change_list_template
. This means that any customization of that template done by the user is effectively ignored. This also means thatdjango-export-import
is not compatible with mixins from other libraries that customize the object tools in the change list view (e.g.,django-admin-sortable2
orreversion
).This issue was reported in #1450
Solution
This makes the
change_list_template
extend whatever customized template is already present in the class hierarchy. This solution is loosely based on the solution to the same issue in django-admin-sortable2.Acceptance Criteria
Additional assertions in admin integration tests cover this use case.