Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Set the user as a foreign key on weight entries, user becomes owner of data entry

Roland Geider7c3fc2ae8b58
diff --git a/weight/models.py b/weight/models.py
index 6ca687498..31dd56c1d 100644
--- a/weight/models.py
+++ b/weight/models.py
@@ -15,6 +15,7 @@
from django.db import models
+from django.contrib.auth.models import User
from django.utils.translation import ugettext as _
class WeightEntry(models.Model):
@@ -22,6 +23,7 @@ class WeightEntry(models.Model):
"""
creation_date = models.DateField(_('Creation date'))
weight = models.FloatField(_('Weight'))
+ user = models.ForeignKey(User, verbose_name = _('User'))
def __unicode__(self):
diff --git a/weight/views.py b/weight/views.py
index 4ba506f94..cafab100c 100644
--- a/weight/views.py
+++ b/weight/views.py
@@ -31,6 +31,7 @@ logger = logging.getLogger('workout_manager.custom')
class WeightForm(ModelForm):
class Meta:
model = WeightEntry
+ exclude=('user',)
@login_required
def add(request, id=None):
@@ -54,7 +55,7 @@ def add(request, id=None):
# If the data is valid, save and redirect
if weight_form.is_valid():
weight = weight_form.save(commit=False)
-
+ weight.user = request.user
weight.save()
return HttpResponseRedirect('/weight/overview/')
@@ -74,7 +75,7 @@ def overview(request):
* http://wijmo.com/wiki/index.php/Scatterchart
"""
template_data = {}
- weights = WeightEntry.objects.all()
+ weights = WeightEntry.objects.filter(user = request.user)
template_data['weights'] = weights
# Process the data to pass it to the JS libraries to generate an SVG image