Self hosted FLOSS fitness/workout, nutrition and weight tracker
Add target values for log values
Roland Geider585354423745
diff --git a/wger/manager/api/serializers.py b/wger/manager/api/serializers.pyindex 15f9c12ba..79398db88 100644--- a/wger/manager/api/serializers.py+++ b/wger/manager/api/serializers.py@@ -452,11 +452,14 @@ class WorkoutLogSerializer(serializers.ModelSerializer):'slot_entry','next_log','exercise',- 'reps','repetition_unit',- 'weight',+ 'reps',+ 'reps_target','weight_unit',+ 'weight',+ 'weight_target','rir',+ 'rir_target','iteration',]diff --git a/wger/manager/migrations/0018_flexible_routines.py b/wger/manager/migrations/0018_flexible_routines.pyindex 3ce7e606c..0d3200263 100644--- a/wger/manager/migrations/0018_flexible_routines.py+++ b/wger/manager/migrations/0018_flexible_routines.py@@ -6,6 +6,8 @@ import django.db.models.deletionfrom django.conf import settingsfrom django.db import migrations, models+import wger.manager.validators+class Migration(migrations.Migration):dependencies = [@@ -103,6 +105,48 @@ class Migration(migrations.Migration):name='date',field=models.DateTimeField(default=datetime.datetime.now, verbose_name='Date'),),+ migrations.AddField(+ model_name='workoutlog',+ name='reps_target',+ field=models.IntegerField(+ null=True,+ validators=[wger.manager.validators.NullMinValueValidator(0)],+ verbose_name='Repetitions',+ ),+ ),+ migrations.AddField(+ model_name='workoutlog',+ name='rir_target',+ field=models.CharField(+ blank=True,+ choices=[+ (None, '------'),+ ('0', 0),+ ('0.5', 0.5),+ ('1', 1),+ ('1.5', 1.5),+ ('2', 2),+ ('2.5', 2.5),+ ('3', 3),+ ('3.5', 3.5),+ ('4', 4),+ ],+ max_length=3,+ null=True,+ verbose_name='RiR',+ ),+ ),+ migrations.AddField(+ model_name='workoutlog',+ name='weight_target',+ field=models.DecimalField(+ decimal_places=2,+ max_digits=5,+ null=True,+ validators=[wger.manager.validators.NullMinValueValidator(0)],+ verbose_name='Weight',+ ),+ ),migrations.AlterField(model_name='workoutsession',name='date',diff --git a/wger/manager/models/log.py b/wger/manager/models/log.pyindex 5f9e5b97c..d71928b02 100644--- a/wger/manager/models/log.py+++ b/wger/manager/models/log.py@@ -32,6 +32,7 @@ from wger.exercises.models import Exercisefrom wger.manager.consts import RIR_OPTIONSfrom wger.manager.managers import WorkoutLogManagerfrom wger.manager.models.session import WorkoutSession+from wger.manager.validators import NullMinValueValidatorfrom wger.utils.cache import reset_workout_log@@ -109,7 +110,7 @@ class WorkoutLog(models.Model):on_delete=models.CASCADE,)"""- The unit of the log. This can be e.g. a repetition, a minute, etc.+ The repetition unit of the log. This can be e.g. a repetition, a minute, etc."""reps = models.IntegerField(@@ -117,18 +118,17 @@ class WorkoutLog(models.Model):validators=[MinValueValidator(0)],)"""- Amount of repetitions, minutes, etc.-- Note that since adding the unit field, the name is no longer correct, but is- kept for compatibility reasons (specially for the REST API).+ Logged amount of repetitions"""- weight = models.DecimalField(- decimal_places=2,- max_digits=5,- verbose_name=_('Weight'),- validators=[MinValueValidator(0)],+ reps_target = models.IntegerField(+ verbose_name=_('Repetitions'),+ validators=[NullMinValueValidator(0)],+ null=True,)+ """+ Target amount of repetitions+ """weight_unit = models.ForeignKey(WeightUnit,@@ -140,6 +140,27 @@ class WorkoutLog(models.Model):The weight unit of the log. This can be e.g. kg, lb, km/h, etc."""+ weight = models.DecimalField(+ decimal_places=2,+ max_digits=5,+ verbose_name=_('Weight'),+ validators=[MinValueValidator(0)],+ )+ """+ Logged amount of weight+ """++ weight_target = models.DecimalField(+ decimal_places=2,+ max_digits=5,+ verbose_name=_('Weight'),+ validators=[NullMinValueValidator(0)],+ null=True,+ )+ """+ Target amount of weight+ """+rir = models.CharField(verbose_name=_('RiR'),max_length=3,@@ -148,10 +169,21 @@ class WorkoutLog(models.Model):choices=RIR_OPTIONS,)"""- Reps in reserve, RiR. The amount of reps that could realistically still be+ Reps in Reserve, RiR. The amount of reps that could realistically still bedone in the set."""+ rir_target = models.CharField(+ verbose_name=_('RiR'),+ max_length=3,+ blank=True,+ null=True,+ choices=RIR_OPTIONS,+ )+ """+ Target Reps in Reserve+ """+# Metaclass to set some other propertiesclass Meta:ordering = ['date', 'reps']diff --git a/wger/manager/validators.py b/wger/manager/validators.pynew file mode 100644index 000000000..38341d7b6--- /dev/null+++ b/wger/manager/validators.py@@ -0,0 +1,30 @@+# This file is part of wger Workout Manager.+#+# wger Workout Manager is free software: you can redistribute it and/or modify+# it under the terms of the GNU Affero General Public License as published by+# the Free Software Foundation, either version 3 of the License, or+# (at your option) any later version.+#+# wger Workout Manager is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU Affero General Public License+# along with Workout Manager. If not, see <http://www.gnu.org/licenses/>.++# Django+from django.core.validators import BaseValidator+from django.utils.deconstruct import deconstructible+++@deconstructible+class NullMinValueValidator(BaseValidator):+ message = 'Ensure this value is either NULL or greater than or equal to %(limit_value)s.'+ code = 'min_value'++ def compare(self, a, b):+ if a is None or b is None:+ return True++ return a < b