Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

History mixin

Tom Bowyer21e062fe1fae
diff --git a/wger/exercises/api/serializers.py b/wger/exercises/api/serializers.py
index 2b7686a36..9b88345fa 100644
--- a/wger/exercises/api/serializers.py
+++ b/wger/exercises/api/serializers.py
@@ -211,6 +211,7 @@ class ExerciseSerializer(serializers.ModelSerializer):
"license",
"license_author",
"variations",
+ "author_history",
)
diff --git a/wger/exercises/models/exercise.py b/wger/exercises/models/exercise.py
index 43119261b..859829bbd 100644
--- a/wger/exercises/models/exercise.py
+++ b/wger/exercises/models/exercise.py
@@ -42,10 +42,13 @@ from wger.utils.cache import (
delete_template_fragment_cache,
reset_workout_canonical_form,
)
-from wger.utils.models import AbstractLicenseModel
+from wger.utils.models import (
+ AbstractLicenseModel,
+ AbstractHistoryMixin,
+)
-class Exercise(AbstractLicenseModel, models.Model):
+class Exercise(AbstractLicenseModel, AbstractHistoryMixin, models.Model):
"""
Model for an exercise
"""
diff --git a/wger/utils/models.py b/wger/utils/models.py
index ac3aec8b5..9eacbb352 100644
--- a/wger/utils/models.py
+++ b/wger/utils/models.py
@@ -86,3 +86,22 @@ class AbstractSubmissionModel(models.Model):
editable=False,
)
"""Status of the submission, e.g. accepted or declined"""
+
+
+class AbstractHistoryMixin(models.Model):
+ """
+ Abstract class used to model specific historical records.
+
+ Utilized in conjunction with simple_history's HistoricalRecords.
+ """
+
+ class Meta:
+ abstract = True
+
+ @property
+ def author_history(self):
+ out = []
+ for history in self.history.all():
+ out.append(history.license_author)
+ return set(out)
+ """Author history is the unique set of license authors from historical records"""