mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2024-11-26 11:34:00 +03:00
fix sites migrations
This commit is contained in:
parent
a5402511b0
commit
ce85e8b6dc
|
@ -65,6 +65,13 @@ class Common(Configuration):
|
|||
)
|
||||
# END MIDDLEWARE CONFIGURATION
|
||||
|
||||
# MIGRATIONS CONFIGURATION
|
||||
MIGRATION_MODULES = {
|
||||
'sites': 'contrib.sites.migrations'
|
||||
}
|
||||
# END MIGRATIONS CONFIGURATION
|
||||
|
||||
|
||||
# DEBUG
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
|
||||
DEBUG = values.BooleanValue(False)
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
import django.contrib.sites.models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Site',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('domain', models.CharField(max_length=100, verbose_name='domain name', validators=[django.contrib.sites.models._simple_domain_name_validator])),
|
||||
('name', models.CharField(max_length=50, verbose_name='display name')),
|
||||
],
|
||||
options={
|
||||
'ordering': ('domain',),
|
||||
'db_table': 'django_site',
|
||||
'verbose_name': 'site',
|
||||
'verbose_name_plural': 'sites',
|
||||
},
|
||||
bases=(models.Model,),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,40 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
def update_site_forward(apps, schema_editor):
|
||||
"""Set site domain and name."""
|
||||
Site = apps.get_model("sites", "Site")
|
||||
Site.objects.update_or_create(
|
||||
id=settings.SITE_ID,
|
||||
defaults={
|
||||
"domain": "{{cookiecutter.domain_name}}",
|
||||
"name": "{{cookiecutter.project_name}}"
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def update_site_backward(apps, schema_editor):
|
||||
"""Revert site domain and name to default."""
|
||||
Site = apps.get_model("sites", "Site")
|
||||
Site.objects.update_or_create(
|
||||
id=settings.SITE_ID,
|
||||
defaults={
|
||||
"domain": "example.com",
|
||||
"name": "example.com"
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('sites', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(update_site_forward, update_site_backward),
|
||||
]
|
|
@ -1,35 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import models, migrations
|
||||
from django.apps import apps as django_apps
|
||||
|
||||
|
||||
def update_site_forward(apps, schema_editor):
|
||||
"""Set site domain and name."""
|
||||
Site = django_apps.get_model("sites", "Site")
|
||||
site = Site.objects.get(id=settings.SITE_ID)
|
||||
site.domain = "{{cookiecutter.domain_name}}"
|
||||
site.name = "{{cookiecutter.project_name}}"
|
||||
site.save()
|
||||
|
||||
|
||||
def update_site_backward(apps, schema_editor):
|
||||
"""Revert site domain and name to default."""
|
||||
Site = django_apps.get_model("sites", "Site")
|
||||
site = Site.objects.get(id=settings.SITE_ID)
|
||||
site.domain = 'example.com'
|
||||
site.name = 'example.com'
|
||||
site.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('users', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(update_site_forward, update_site_backward),
|
||||
]
|
Loading…
Reference in New Issue
Block a user