mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2025-12-23 18:29:23 -05:00
MealPlan from/to date to datetime, added time to MealType
This commit is contained in:
@@ -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)
|
||||
]
|
||||
@@ -417,7 +417,6 @@ class ConnectorConfig(models.Model, PermissionModelMixin):
|
||||
objects = ScopedManager(space='space')
|
||||
|
||||
|
||||
|
||||
class UserPreference(models.Model, PermissionModelMixin):
|
||||
# Themes
|
||||
BOOTSTRAP = 'BOOTSTRAP'
|
||||
@@ -1135,6 +1134,7 @@ class MealType(models.Model, PermissionModelMixin):
|
||||
name = models.CharField(max_length=128)
|
||||
order = models.IntegerField(default=0)
|
||||
color = models.CharField(max_length=7, blank=True, null=True)
|
||||
time = models.TimeField(null=True, blank=True)
|
||||
default = models.BooleanField(default=False, blank=True)
|
||||
created_by = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
|
||||
@@ -1158,8 +1158,8 @@ class MealPlan(ExportModelOperationsMixin('meal_plan'), models.Model, Permission
|
||||
shared = models.ManyToManyField(User, blank=True, related_name='plan_share')
|
||||
meal_type = models.ForeignKey(MealType, on_delete=models.CASCADE)
|
||||
note = models.TextField(blank=True)
|
||||
from_date = models.DateField()
|
||||
to_date = models.DateField()
|
||||
from_date = models.DateTimeField()
|
||||
to_date = models.DateTimeField()
|
||||
|
||||
space = models.ForeignKey(Space, on_delete=models.CASCADE)
|
||||
objects = ScopedManager(space='space')
|
||||
|
||||
@@ -355,7 +355,7 @@ class MealTypeSerializer(SpacedModelSerializer, WritableNestedModelSerializer):
|
||||
class Meta:
|
||||
list_serializer_class = SpaceFilterSerializer
|
||||
model = MealType
|
||||
fields = ('id', 'name', 'order', 'color', 'default', 'created_by')
|
||||
fields = ('id', 'name', 'order', 'time', 'color', 'default', 'created_by')
|
||||
read_only_fields = ('created_by',)
|
||||
|
||||
|
||||
@@ -1030,7 +1030,7 @@ class MealPlanSerializer(SpacedModelSerializer, WritableNestedModelSerializer):
|
||||
shared = UserSerializer(many=True, required=False, allow_null=True)
|
||||
shopping = serializers.SerializerMethodField('in_shopping')
|
||||
|
||||
to_date = serializers.DateField(required=False)
|
||||
to_date = serializers.DateTimeField(required=False)
|
||||
|
||||
def get_note_markdown(self, obj):
|
||||
return markdown(obj.note)
|
||||
|
||||
Reference in New Issue
Block a user