question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: Swappability of main models

See original GitHub issue

So I have this problem with Wagtail that sometimes (or more like, usually) main models (wagtailcore.Page, wagtailimages.Image, etc.) need to have some additional functionality or overrides to existing functionality.

Consider for example making Page translatable without duplicating trees. One would use something like django-modeltranslation to do that but then all the slug/url_path related functions have to be overriden to handle translated urls properly. You could of course write a Mixin and extend all your Page extending models with that, but some of Page’s core functionality doesn’t necessarily use instance.specific which means that the only way to override Page’s functionality is monkey-patching. And everyone knows how bad monkey-patching is 😃

Django has this very underused feature called swappable models (as used in django.contrib.auth.User). It would be great if Wagtail’s core models would be swappable. This would be as simple as moving all implementation to abstract base models (like what is already the case with Image model) and leaving actual model empty with only swappable option in it’s Meta. Like this:

class Page(BasePage):
    class Meta(BasePage.Meta):
        swappable = 'WAGTAIL_PAGE_MODEL'

Then implement a simple function get_page_model which returns the actual Page model and replace all cases of direct Page class usage with get_page_model().

I have attempted a similar refactoring in django-filer and there are really only pros and no cons with this approach. It would all be 100% backwards-compatible. On the other hand, a lot of flexibility is gained this way.

Now I would be willing to provide a pull request for this, but first I wanted to check whether core developers would support such an idea.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:8
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
dmarcelinocommented, Feb 20, 2019

@sonnybaker, from wagtail-modeltranslation’s perspective a swappable Page model would be a game changer. It would make the implementation cleaner without recurring to monkey patching Page.

cc: @DiogoMarques29

1reaction
m5seppalcommented, May 26, 2021

Any ongoing activity with this feature? This would be very much needed. Most of the issues I’m having with the Wagtail at the moment comes from the fact that there is no way to extend the Page model.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Introduce an AbstractPage class to allow base page fields to ...
References to base page model in WT code make overriding difficult #2022 ... Feature request: Swappability of main models #3282.
Read more >
What does it mean to hot swap in computing? - TechTarget
Hot swap is a required feature in fault-tolerant systems with redundant ... Hot swappable SATA drives require a controller and a compliant power...
Read more >
Dimensional Data Modelling: 6 Critical Aspects
This article will introduce the concepts and features of Dimensional Data Modelling, the components that make up a Dimensional Data Model, ...
Read more >
Hot swapping - Wikipedia
Hot swapping is the replacement or addition of components to a computer system without ... Components which have such functionality are said to...
Read more >
Customizing authentication in Django
That's the basic authentication backend that checks the Django users database ... dynamic dependency feature for swappable models, the model referenced by ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found