feat: automatically convert standard model admins for unfold #1331
+100
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When model admin is not inherited from unfold's ModelAdmin - then the form looks unstyled. It's easy to avoid with own applications, but makes it a little tedious to install and use third-party apps - because I need to unregister and replace builtin admin classes.
I thought it would be great if third party apps would just work at least for simple cases. So I made this simple slightly magic trick, that does work for me at least on simple cases.
When new "unfold.contrib.convert" is added to INSTALLED_APPS (in the last position) it:
1. Finds all admin classes that are not subclasses of unfold.admin.ModelAdmin
2. Unregisters them
3. Creates new classes that inherit from both the original admin and unfold.admin.ModelAdmin
4. Fixes any inlines by creating new classes that inherit from unfold inline classes
5. Registers the new classes
This is a very basic conversion, but it does reduces a friction of using unfold with third party apps for me.