Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Backport exercise aliases from feature/exercise-crowdsourcing

Roland Geider879a54f46a4b
diff --git a/wger/exercises/migrations/0016_exercisealias.py b/wger/exercises/migrations/0016_exercisealias.py
new file mode 100644
index 000000000..c065f2ad5
--- /dev/null
+++ b/wger/exercises/migrations/0016_exercisealias.py
@@ -0,0 +1,22 @@
+# Generated by Django 3.2.10 on 2022-02-17 21:05
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('exercises', '0015_exercise_videos'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='Alias',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('alias', models.CharField(max_length=200, verbose_name='Alias for an exercise')),
+ ('exercise', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='exercises.exercise', verbose_name='Exercise')),
+ ],
+ ),
+ ]
diff --git a/wger/exercises/models/__init__.py b/wger/exercises/models/__init__.py
index af78f086c..c26f43fa6 100644
--- a/wger/exercises/models/__init__.py
+++ b/wger/exercises/models/__init__.py
@@ -24,3 +24,4 @@ from .image import ExerciseImage
from .muscle import Muscle
from .variation import Variation
from .video import ExerciseVideo
+from .exercise_alias import Alias
diff --git a/wger/exercises/models/exercise_alias.py b/wger/exercises/models/exercise_alias.py
new file mode 100644
index 000000000..85938dfc5
--- /dev/null
+++ b/wger/exercises/models/exercise_alias.py
@@ -0,0 +1,61 @@
+# This file is part of wger Workout Manager <https://github.com/wger-project>.
+# Copyright (C) 2013 - 2021 wger Team
+#
+# 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 Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Django
+from django.db import models
+from django.utils.translation import gettext_lazy as _
+
+# wger
+from wger.utils.cache import reset_workout_canonical_form
+
+# Local
+from .exercise import Exercise
+
+
+class Alias(models.Model):
+ """
+ Model for an exercise (name)alias
+ """
+ exercise = models.ForeignKey(
+ Exercise,
+ verbose_name=_('Exercise'),
+ on_delete=models.CASCADE
+ )
+ alias = models.CharField(
+ max_length=200,
+ verbose_name=_('Alias for an exercise'),
+ )
+
+ def __str__(self):
+ """
+ Return a more human-readable representation
+ """
+ return self.alias
+
+ def delete(self, *args, **kwargs):
+ """
+ Reset cached workouts
+ """
+ for setting in self.exercise.setting_set.all():
+ reset_workout_canonical_form(setting.set.exerciseday.training.pk)
+
+ super(Alias, self).delete(*args, **kwargs)
+
+ def get_owner_object(self):
+ """
+ Comment has no owner information
+ """
+ return False