{"action":"created","issue":{"url":"https://api.github.com/repos/wagtail/wagtail/issues/3282","repository_url":"https://api.github.com/repos/wagtail/wagtail","labels_url":"https://api.github.com/repos/wagtail/wagtail/issues/3282/labels{/name}","comments_url":"https://api.github.com/repos/wagtail/wagtail/issues/3282/comments","events_url":"https://api.github.com/repos/wagtail/wagtail/issues/3282/events","html_url":"https://github.com/wagtail/wagtail/issues/3282","id":201630617,"node_id":"MDU6SXNzdWUyMDE2MzA2MTc=","number":3282,"title":"Swappability of main models","user":{"login":"skirsdeda","id":7189652,"node_id":"MDQ6VXNlcjcxODk2NTI=","avatar_url":"https://avatars0.githubusercontent.com/u/7189652?v=4","gravatar_id":"","url":"https://api.github.com/users/skirsdeda","html_url":"https://github.com/skirsdeda","followers_url":"https://api.github.com/users/skirsdeda/followers","following_url":"https://api.github.com/users/skirsdeda/following{/other_user}","gists_url":"https://api.github.com/users/skirsdeda/gists{/gist_id}","starred_url":"https://api.github.com/users/skirsdeda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/skirsdeda/subscriptions","organizations_url":"https://api.github.com/users/skirsdeda/orgs","repos_url":"https://api.github.com/users/skirsdeda/repos","events_url":"https://api.github.com/users/skirsdeda/events{/privacy}","received_events_url":"https://api.github.com/users/skirsdeda/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2017-01-18T16:54:03Z","updated_at":"2018-11-21T03:08:24Z","closed_at":null,"author_association":"NONE","body":"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. \r\n\r\nConsider 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 :)\r\n\r\nDjango 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:\r\n```python\r\nclass Page(BasePage):\r\n    class Meta(BasePage.Meta):\r\n        swappable = 'WAGTAIL_PAGE_MODEL'\r\n```\r\nThen 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()```.\r\n\r\nI 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.\r\n\r\nNow 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."},"comment":{"url":"https://api.github.com/repos/wagtail/wagtail/issues/comments/440512521","html_url":"https://github.com/wagtail/wagtail/issues/3282#issuecomment-440512521","issue_url":"https://api.github.com/repos/wagtail/wagtail/issues/3282","id":440512521,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0MDUxMjUyMQ==","user":{"login":"dfirst","id":3999352,"node_id":"MDQ6VXNlcjM5OTkzNTI=","avatar_url":"https://avatars2.githubusercontent.com/u/3999352?v=4","gravatar_id":"","url":"https://api.github.com/users/dfirst","html_url":"https://github.com/dfirst","followers_url":"https://api.github.com/users/dfirst/followers","following_url":"https://api.github.com/users/dfirst/following{/other_user}","gists_url":"https://api.github.com/users/dfirst/gists{/gist_id}","starred_url":"https://api.github.com/users/dfirst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dfirst/subscriptions","organizations_url":"https://api.github.com/users/dfirst/orgs","repos_url":"https://api.github.com/users/dfirst/repos","events_url":"https://api.github.com/users/dfirst/events{/privacy}","received_events_url":"https://api.github.com/users/dfirst/received_events","type":"User","site_admin":false},"created_at":"2018-11-21T03:08:24Z","updated_at":"2018-11-21T03:08:24Z","author_association":"NONE","body":"Hi everyone. I want to propose an idea of how to make wagtail apps more flexible. Here is raw proof of concept with tests passes:\r\nhttps://github.com/dfirst/wagtail/tree/PROPOSE_forking_wagtail_apps\r\nShort summary of idea:\r\n1. Use dynamic imports of classes we want to be customizable.\r\n2. For customization i used idea of locale fork of wagtail and dynamic importer. First importer check if class exists in fork if not then it import it from root.(fork path can be controlled WAGTAIL_FORK)\r\n3. If user want to customize a model then he should copy migrations and set MIGRATION_MODULES.\r\n4. The idea can be implemented without breaking changes step by step.\r\nWhat do you think about it? If the idea is interesting we can create a plan and i will finish it."}}
{"actor":{"display_login":"dfirst"}}