Self hosted FLOSS fitness/workout, nutrition and weight tracker
Add method to get the object that stores reference to owner
Roland Geider9529278a3819
diff --git a/exercises/models.py b/exercises/models.pyindex d39eaec9d..977711aff 100644--- a/exercises/models.py+++ b/exercises/models.py@@ -71,6 +71,13 @@ class ExerciseCategory(models.Model):"""Return a more human-readable representation"""return self.name++ def get_owner_object(self):+ """+ Category has no owner information+ """+ return False+@@ -101,6 +108,14 @@ class Exercise(models.Model):"""return self.name++ def get_owner_object(self):+ """+ Exercise has no owner information+ """+ return False++class ExerciseComment(models.Model):"""Model for an exercise comment"""@@ -113,3 +128,10 @@ class ExerciseComment(models.Model):"""Return a more human-readable representation"""return self.comment++ def get_owner_object(self):+ """+ Comment has no owner information+ """+ return self+diff --git a/manager/models.py b/manager/models.pyindex e416b67c7..9ba55d224 100644--- a/manager/models.py+++ b/manager/models.py@@ -58,6 +58,13 @@ For example 'Focus on back' or 'Week 1 of program xy'.'''))"""Return a more human-readable representation"""return str(self.creation_date)++ def get_owner_object(self):+ """+ Returns the object that has owner information+ """+ return self+class DaysOfWeek(models.Model):"""Model for the days of the week@@ -87,10 +94,16 @@ class Day(models.Model):verbose_name = _('Day'))def __unicode__(self):- """Return a more human-readable representation+ """+ Return a more human-readable representation"""return "%s for TP %s" % (self.description, unicode(self.training))-++ def get_owner_object(self):+ """+ Returns the object that has owner information+ """+ return self.trainingclass Set(models.Model):"""Model for a set of exercises@@ -113,6 +126,11 @@ class Set(models.Model):"""return "Set %s for %s" % (self.order or '-/-', unicode(self.exerciseday))+ def get_owner_object(self):+ """+ Returns the object that has owner information+ """+ return self.exerciseday.trainingclass Setting(models.Model):@@ -135,6 +153,12 @@ class Setting(models.Model):"""return "settings for exercise %s in set %s" % (self.exercise.id, self.set.id)+ def get_owner_object(self):+ """+ Returns the object that has owner information+ """+ return self.set.exerciseday.training+class UserProfile(models.Model):# This field is required.@@ -156,6 +180,8 @@ a nutritional plan. These ingredients are extracted from a list providedby the US Department of Agriculture. It is extremely complete, with around7000 entries, but can be somewhat overwhelming and make the search difficult.'''))++# Every new user gets a profiledef create_user_profile(sender, instance, created, **kwargs):if created:UserProfile.objects.create(user=instance)diff --git a/nutrition/models.py b/nutrition/models.pyindex 094bd2f0e..0cb28bd5a 100644--- a/nutrition/models.py+++ b/nutrition/models.py@@ -88,6 +88,14 @@ class NutritionPlan(models.Model):if item.ingredient.sodium:nutritional_info['sodium'] += item.ingredient.sodium * item.amount_gramm / 100return nutritional_info+++ def get_owner_object(self):+ """+ Returns the object that has owner information+ """+ return self+class Ingredient(models.Model):""" An ingredient, with some approximate nutrition values@@ -151,6 +159,13 @@ class Ingredient(models.Model):return "%s" % (self.name, )+ def get_owner_object(self):+ """+ Ingredient has no owner information+ """+ return False++class Meal(models.Model):""" A meal"""@@ -170,6 +185,13 @@ class Meal(models.Model):return "%s Meal" % (self.order,)+ def get_owner_object(self):+ """+ Returns the object that has owner information+ """+ return self.plan++class MealItem(models.Model):""" An item (component) of a meal"""@@ -194,3 +216,10 @@ class MealItem(models.Model):"""Return a more human-readable representation"""return "%s %s %s" % (self.order, self.amount_gramm or self.amount_freetext, self.ingredient)++ def get_owner_object(self):+ """+ Returns the object that has owner information+ """+ return self.meal.plan+diff --git a/weight/models.py b/weight/models.pyindex af95c95db..eba67c07d 100644--- a/weight/models.py+++ b/weight/models.py@@ -37,3 +37,11 @@ class WeightEntry(models.Model):"""Return a more human-readable representation"""return "%s: %s kg" % (self.creation_date, self.weight)+++ def get_owner_object(self):+ """+ Returns the object that has owner information+ """+ return self+