Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Make the day a many-to-many relationship

Roland Geiderd5a94e042253
diff --git a/manager/models.py b/manager/models.py
index 7767d1c39..c8d07a885 100644
--- a/manager/models.py
+++ b/manager/models.py
@@ -58,6 +58,23 @@ For example 'Focus on back' or 'Week 1 of program xy'.'''))
"""
return str(self.creation_date)
+class DaysOfWeek(models.Model):
+ """Model for the days of the week
+
+ This model is needed so that 'Day' can have multiple days of the week selected
+ """
+
+ day_of_week = models.IntegerField(max_length=1,
+ choices=DAYS_OF_WEEK_CHOICES,
+ verbose_name = _('Day of the week'))
+
+
+ def __unicode__(self):
+ """Return a more human-readable representation
+ """
+ return self.day_of_week
+
+
class Day(models.Model):
"""Model for a training day
"""
@@ -66,7 +83,8 @@ class Day(models.Model):
description = models.CharField(max_length=100,
verbose_name = _('Description'),
help_text=_('Ususally a description about what parts are trained, like "Arms" or "Pull Day"'))
- day = models.IntegerField(max_length=1, choices=DAYS_OF_WEEK_CHOICES, verbose_name = _('Day'))
+ day = models.ManyToManyField(DaysOfWeek,
+ verbose_name = _('Day'))
def __unicode__(self):
"""Return a more human-readable representation
diff --git a/manager/views.py b/manager/views.py
index 005ee336b..786359dd8 100644
--- a/manager/views.py
+++ b/manager/views.py
@@ -23,6 +23,7 @@ from django.http import HttpResponseRedirect
from django.http import HttpResponseForbidden
from django.forms import ModelForm
from django.forms.models import modelformset_factory
+from django.forms import SelectMultiple
from django.core.context_processors import csrf
from django.core.exceptions import ObjectDoesNotExist
from django.contrib.auth.decorators import login_required
@@ -495,6 +496,7 @@ class DayForm(ModelForm):
class Meta:
model = Day
exclude=('training',)
+
@login_required
def edit_day(request, id, day_id=None):
@@ -530,6 +532,8 @@ def edit_day(request, id, day_id=None):
day.training = workout
day.save()
+ day_form.save_m2m()
+
return HttpResponseRedirect('/workout/%s/view/' % id)
else:
day_form = DayForm(instance=day)