-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* model changes and migrations to support fractions * adding some comments and removing quantity * updating models to allow floats
- Loading branch information
Showing
4 changed files
with
65 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Generated by Django 2.0.1 on 2018-03-30 10:55 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('ingredient', '0008_auto_20180129_1456'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='ingredient', | ||
name='denominator', | ||
field=models.FloatField(default=1, verbose_name='denominator'), | ||
), | ||
migrations.AddField( | ||
model_name='ingredient', | ||
name='numerator', | ||
field=models.FloatField(default=1, verbose_name='numerator'), | ||
), | ||
] |
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,26 @@ | ||
# Generated by Django 2.0.1 on 2018-03-30 10:58 | ||
|
||
from django.db import migrations | ||
from fractions import Fraction | ||
|
||
|
||
def make_fraction(apps, schema_editor): | ||
# We can't import the Ingredient model directly as it may be a newer | ||
# version than this migration expects. We use the historical version. | ||
Ingredient = apps.get_model('ingredient', 'Ingredient') | ||
for i in Ingredient.objects.all(): | ||
fraction = Fraction(i.quantity).limit_denominator(100) | ||
i.numerator = fraction.numerator | ||
i.denominator = fraction.denominator | ||
i.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('ingredient', '0009_auto_20180330_1055'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(make_fraction), | ||
] |
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