Custom Image and Documents Models should use Django Swappable Models
Is your proposal related to a problem?
Wagtail currently provides support for Custom Image and Document models as described in Custom image model and Custom document model. However, it does not use the swappable model feature of Django (available since version 1.5); see Fixed #3011 -- Added swappable auth.User models.
This means that when a custom model is used, the table for the default model is still created; this causes conflicts if both models have the same name i.e. wagtailimages.image and media.image see #5119, It can also hide errors such as some model directly referring to wagtailimages.image if swappable models as used this will cause a migration error as the table doesn't exist, alerting the developer to the bad reference rather than just referring to an empty table and causing runtime bugs.
Also, See #5789
Describe the solution you'd like
Make wagtailimages.image, wagtailimages.rendition and wagtaildocs.document swappable models like auth.user form django.contrib.auth see
Fixed #3011 -- Added swappable auth.User models for how auth.user was done plus added the test for testing the feature.
I believe this just requires adding swappable = "{custom_model_setting}" to the meta class for each model, and everything should just work as you have already implemented the custom model dependency in Wagtail; this should just cause the Django ORM to substitute the new model in the database. But I could be missing something as I've only skimmed through your implementation to work out why I had a naming conflict occurring for my custom model.
Describe alternatives you've considered
The only alternative is to use illogical names for custom models to avoid conflicts; this still dosen't address the possibly of silent reference error due to the default table still existing.
Additional context
Related Issues (mentioned above):
- #5119
- #5789
Source: wagtail/wagtail