forked from TandoorRecipes/recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MealPlan from/to date to datetime, added time to MealType
- Loading branch information
1 parent
c87964f
commit 4b551c5
Showing
3 changed files
with
51 additions
and
5 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
cookbook/migrations/0218_alter_mealplan_from_date_alter_mealplan_to_date.py
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,46 @@ | ||
# Generated by Django 4.2.11 on 2024-05-01 10:56 | ||
from datetime import timedelta | ||
|
||
from django.db import migrations, models | ||
from django_scopes import scopes_disabled | ||
|
||
|
||
def timezone_correction(apps, schema_editor): | ||
# when converting from date to datetime the field becomes timezone aware and defaults to 00:00:00 UTC | ||
# this will be converted to a local datetime on the client which, for all negative offset timezones, | ||
# would mean that the plan item shows one day prior to the previous planning date | ||
# by setting the time on the old entries to 11:00 this issue will be limited to a very small number of people (see https://en.wikipedia.org/wiki/Time_zone#/media/File:World_Time_Zones_Map.svg) | ||
# the server timezone could be used to guess zone of most of the clients but that would also not be perfect so this much simpler alternative is chosen | ||
with scopes_disabled(): | ||
MealPlan = apps.get_model('cookbook', 'MealPlan') | ||
meal_plans = MealPlan.objects.all() | ||
for mp in meal_plans: | ||
mp.from_date += timedelta(hours=12) | ||
mp.to_date += timedelta(hours=12) | ||
|
||
MealPlan.objects.bulk_update(meal_plans, ['from_date', 'to_date'], batch_size=1000) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
('cookbook', '0217_alter_userpreference_default_page'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='mealtype', | ||
name='time', | ||
field=models.TimeField(blank=True, null=True), | ||
), | ||
migrations.AlterField( | ||
model_name='mealplan', | ||
name='from_date', | ||
field=models.DateTimeField(), | ||
), | ||
migrations.AlterField( | ||
model_name='mealplan', | ||
name='to_date', | ||
field=models.DateTimeField(), | ||
), | ||
migrations.RunPython(timezone_correction) | ||
] |
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