Self hosted FLOSS fitness/workout, nutrition and weight tracker
wip: collect all authors for ExerciseBase
Adam Petík50dda1d39c41
diff --git a/wger/exercises/api/serializers.py b/wger/exercises/api/serializers.pyindex 088e8218c..6d7487c03 100644--- a/wger/exercises/api/serializers.py+++ b/wger/exercises/api/serializers.py@@ -369,4 +369,5 @@ class ExerciseBaseInfoSerializer(serializers.ModelSerializer):"images","videos","author_history",+ "total_authors_history",]diff --git a/wger/exercises/models/base.py b/wger/exercises/models/base.pyindex f9e4b90b9..036b6287b 100644--- a/wger/exercises/models/base.py+++ b/wger/exercises/models/base.py@@ -40,6 +40,7 @@ from wger.utils.constants import ENGLISH_SHORT_NAMEfrom wger.utils.models import (AbstractHistoryMixin,AbstractLicenseModel,+ collect_models_author_history,)# Local@@ -106,6 +107,20 @@ class ExerciseBase(AbstractLicenseModel, AbstractHistoryMixin, models.Model):history = HistoricalRecords()"""Edit history"""+ @property+ def total_authors_history(self):+ """+ All athors history related to the BaseExercise.+ """+ history = self.author_history+ collect_for_models = [+ *self.exercises.all(),+ *self.exercisevideo_set.all(),+ *self.exerciseimage_set.all(),+ ]+ history.union(collect_models_author_history(collect_for_models))+ return history+def __str__(self):"""Return a more human-readable representationdiff --git a/wger/exercises/models/video.py b/wger/exercises/models/video.pyindex d6bd97862..37dccb353 100644--- a/wger/exercises/models/video.py+++ b/wger/exercises/models/video.py@@ -92,7 +92,7 @@ class ExerciseVideo(AbstractLicenseModel, models.Model):verbose_name=_('Exercise'),on_delete=models.CASCADE,)- """The exercise the image belongs to"""+ """The exercise the video belongs to"""is_main = models.BooleanField(verbose_name=_('Main video'),diff --git a/wger/utils/models.py b/wger/utils/models.pyindex cbfa6d696..bd4ef5b71 100644--- a/wger/utils/models.py+++ b/wger/utils/models.py@@ -17,7 +17,6 @@# Djangofrom django.db import modelsfrom django.utils.translation import gettext_lazy as _-# wgerfrom wger.core.models import Licensefrom wger.utils.constants import DEFAULT_LICENSE_ID@@ -95,10 +94,28 @@ class AbstractHistoryMixin():Utilized in conjunction with simple_history's HistoricalRecords."""+@propertydef author_history(self):"""Author history is the unique set of license authors from historical records"""- out = set()- for history in set(self.history.all()):- out.add(history.license_author)- return set(out)+ return collect_model_author_history(self)+++def collect_model_author_history(model):+ """+ Get unique set of license authors from historical records from model.+ """+ out = set()+ for history in set(model.history.all()):+ out.add(history.license_author)+ return out+++def collect_models_author_history(models):+ """+ Get unique set of license authors from historical records from models.+ """+ out = set()+ for model in models:+ out.union(collect_model_author_history(model))+ return out