diff --git a/rowers/models.py b/rowers/models.py index 87585c37..37177144 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -344,12 +344,17 @@ class WorkoutForm(ModelForm): duration = forms.TimeInput(format='%H:%M:%S.%f') class Meta: model = Workout - fields = ['name','date','starttime','duration','distance','workouttype','notes'] + fields = ['name','date','starttime','duration','distance','workouttype','boattype','notes'] widgets = { 'date': DateInput(), 'notes': forms.Textarea, 'duration': forms.TimeInput(format='%H:%M:%S.%f'), } + + def __init__(self, *args, **kwargs): + super(WorkoutForm, self).__init__(*args, **kwargs) + if self.instance.workouttype != 'water': + del self.fields['boattype'] class AdvancedWorkoutForm(ModelForm): class Meta: diff --git a/rowers/views.py b/rowers/views.py index 79d3a137..c0d4b14c 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -3037,6 +3037,10 @@ def workout_edit_view(request,id=0,message="",successmessage=""): duration = form.cleaned_data['duration'] distance = form.cleaned_data['distance'] notes = form.cleaned_data['notes'] + try: + boattype = request.POST['boattype'] + except KeyError: + boattype = Workout.objects.get(id=id).boattype startdatetime = (str(date) + ' ' + str(starttime)) startdatetime = datetime.datetime.strptime(startdatetime, "%Y-%m-%d %H:%M:%S") @@ -3054,6 +3058,7 @@ def workout_edit_view(request,id=0,message="",successmessage=""): row.notes = notes row.duration = duration row.distance = distance + row.boattype = boattype row.save() # change data in csv file # startdatetime = dateutil.parser.parse("{}, {}".format(date,starttime))