Skip to content

Commit d88eebe

Browse files
committed
Add start and end fields to the nutritional plan models
1 parent b678b0c commit d88eebe

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

wger/nutrition/api/serializers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ class Meta:
316316
fields = [
317317
'id',
318318
'creation_date',
319+
'start',
320+
'end',
319321
'description',
320322
'only_logging',
321323
'goal_energy',
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Generated by Django 5.2.3 on 2025-06-26 08:51
2+
3+
import django.utils.timezone
4+
from django.db import migrations, models
5+
6+
7+
def copy_creation_date_to_start(apps, schema_editor):
8+
NutritionPlan = apps.get_model('nutrition', 'NutritionPlan')
9+
NutritionPlan.objects.all().update(start=models.F('creation_date'))
10+
11+
12+
class Migration(migrations.Migration):
13+
dependencies = [
14+
('nutrition', '0025_add_last_image_check'),
15+
]
16+
17+
operations = [
18+
migrations.AddField(
19+
model_name='nutritionplan',
20+
name='end',
21+
field=models.DateField(blank=True, null=True, verbose_name='End date'),
22+
),
23+
migrations.AddField(
24+
model_name='nutritionplan',
25+
name='start',
26+
field=models.DateField(default=django.utils.timezone.now, verbose_name='Start date'),
27+
preserve_default=False,
28+
),
29+
migrations.RunPython(
30+
copy_creation_date_to_start,
31+
reverse_code=migrations.RunPython.noop
32+
),
33+
]

wger/nutrition/models/plan.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
from wger.utils.cache import cache_mapper
3232
from wger.weight.models import WeightEntry
3333

34-
3534
logger = logging.getLogger(__name__)
3635

3736

@@ -59,6 +58,16 @@ class Meta:
5958
auto_now_add=True,
6059
)
6160

61+
start = models.DateField(
62+
_('Start date'),
63+
)
64+
65+
end = models.DateField(
66+
_('End date'),
67+
null=True,
68+
blank=True,
69+
)
70+
6271
description = models.CharField(
6372
max_length=80,
6473
blank=True,

0 commit comments

Comments
 (0)