-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make Recipe locale and country selection many-to-many
Fixes bug 1248263.
- Loading branch information
Showing
5 changed files
with
150 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.9 on 2016-02-18 20:24 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('recipes', '0015_auto_20160217_1819'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Country', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('code', models.CharField(max_length=255, unique=True)), | ||
('name', models.CharField(max_length=255)), | ||
('order', models.IntegerField()), | ||
], | ||
options={ | ||
'ordering': ['order', 'name'], | ||
}, | ||
), | ||
migrations.AddField( | ||
model_name='locale', | ||
name='order', | ||
field=models.IntegerField(default=100), | ||
preserve_default=False, | ||
), | ||
migrations.RemoveField( | ||
model_name='recipe', | ||
name='country', | ||
), | ||
migrations.RemoveField( | ||
model_name='recipe', | ||
name='locale', | ||
), | ||
migrations.AddField( | ||
model_name='recipe', | ||
name='locales', | ||
field=models.ManyToManyField(blank=True, to='recipes.Locale'), | ||
), | ||
migrations.AddField( | ||
model_name='recipe', | ||
name='countries', | ||
field=models.ManyToManyField(blank=True, to='recipes.Country'), | ||
), | ||
migrations.AlterModelOptions( | ||
name='locale', | ||
options={'ordering': ['order', 'code']}, | ||
), | ||
] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.9 on 2016-02-18 19:03 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations | ||
|
||
from django_countries import countries | ||
|
||
|
||
def add_countries(apps, schema_editor): | ||
Country = apps.get_model('recipes', 'Country') | ||
for (code, name) in countries: | ||
if code == 'US': | ||
order = 0 | ||
else: | ||
order = 100 | ||
|
||
Country.objects.update_or_create(code=code, defaults={ | ||
'name': name, | ||
'order': order, | ||
}) | ||
|
||
|
||
def remove_countries(apps, schema_editor): | ||
Country = apps.get_model('recipes', 'Country') | ||
Country.objects.all().delete() | ||
|
||
|
||
def set_locale_sort_order(apps, schema_editor): | ||
Locale = apps.get_model('recipes', 'Locale') | ||
english = Locale.objects.get(code='en-US') | ||
english.order = 0 | ||
english.save() | ||
|
||
|
||
def noop(apps, schema_editor): | ||
pass | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('recipes', '0016_auto_20160218_2024'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(add_countries, remove_countries), | ||
migrations.RunPython(set_locale_sort_order, noop), | ||
] |
This file contains 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
This file contains 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