Created
December 11, 2017 10:57
-
-
Save allyjweir/1442f67daa09aa30cc8a028afabaae3a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf import settings | |
from django.db import migrations | |
''' | |
Django-allauth requires a site to be configured within the django.contrib.sites | |
application. This is used when constructing URLs for the password reset emails | |
and email confirmations etc. Therefore, it is important that this value is | |
customised so that we can redirect those requests to redirect within the given | |
application we need them to be. | |
For example, the auth service is hosted at a.com and the website at b.com. We | |
want any URLs included in emails etc sent from auth-service to have b.com | |
embedded in them so that we portray a consistent URL to all external users. Our | |
services will deal with redirection of those requests. | |
''' | |
def forward_func(apps, schema_editor): | |
domain = settings.CUSTOM_SITE_DOMAIN | |
name = settings.CUSTOM_SITE_NAME | |
Site = apps.get_model("sites", "Site") | |
db_alias = schema_editor.connection.alias | |
Site.objects.using(db_alias).create(domain=domain, name=name) | |
def reverse_func(apps, schema_editor): | |
domain = settings.CUSTOM_SITE_DOMAIN | |
name = settings.CUSTOM_SITE_NAME | |
Site = apps.get_model("sites", "Site") | |
db_alias = schema_editor.connection.alias | |
Site.objects.using(db_alias).filter(domain=domain, name=name).delete() | |
class Migration(migrations.Migration): | |
dependencies = [ | |
('django.contrib.sites', '__latest__') | |
] | |
operations = [ | |
migrations.RunPython(forward_func, reverse_func) | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment