Self hosted FLOSS fitness/workout, nutrition and weight tracker
Only show available weekdays on the day edit form
Roland Geider89c4afb01c5f
diff --git a/manager/views.py b/manager/views.pyindex 37f12e8ce..36a19487d 100644--- a/manager/views.py+++ b/manager/views.py@@ -37,6 +37,7 @@ from django.contrib.auth.forms import AuthenticationFormfrom django.contrib.auth.forms import UserCreationFormfrom manager.models import DAYS_OF_WEEK_CHOICES+from manager.models import DaysOfWeekfrom manager.models import TrainingSchedulefrom manager.models import Dayfrom manager.models import Set@@ -525,6 +526,18 @@ def edit_day(request, id, day_id=None):workout = get_object_or_404(TrainingSchedule, pk=id, user=request.user)template_data['workout'] = workout+ # Calculate the free days+ used_days = []+ for day in workout.day_set.all():+ for weekday in day.day.all():+ if day.id != int(day_id):+ logger.debug("day.id: %s, day_id: %s" % (day.id, day_id))+ used_days.append(weekday.id)+ used_days.sort()+ logger.debug(used_days)+++# Load day# We check for string 'None' because we might get this from the templateif not day_id or day_id == 'None':@@ -537,6 +550,7 @@ def edit_day(request, id, day_id=None):return HttpResponseForbidden()template_data['day'] = day+# Process requestif request.method == 'POST':day_form = DayForm(request.POST, instance=day)@@ -552,6 +566,11 @@ def edit_day(request, id, day_id=None):return HttpResponseRedirect('/workout/%s/view/' % id)else:day_form = DayForm(instance=day)++ # Set here the query set to filter out used days of the week+ # (used in the sense that other training days on the same workout already have them set)+ day_form.fields['day'].queryset=DaysOfWeek.objects.exclude(id__in=used_days)+template_data['day_form'] = day_formreturn render_to_response('day/edit.html',