def testExercizeAndSet(self): ex = Exercize(name="Bench press", muscle_group="Chest") key = ex.get_key() ex.save() print "\n\nKey {0}".format(repr(key)) s_ex = Exercize.load(key) self.assertEqual(s_ex.name, ex.name) self.assertEqual(s_ex.muscle_group, ex.muscle_group) ex_set = ExercizeSet(exercize=ex, weight=80, reps=10) set_key = ex_set.get_key() ex_set.save() print "\n\nSet key {0}".format(repr(set_key)) s_ex_set = ExercizeSet.load(set_key) self.assertEqual(s_ex_set.exercize.get_key(), ex.get_key()) self.assertEqual(s_ex_set.weight, ex_set.weight) self.assertEqual(s_ex_set.reps, ex_set.reps) Exercize.delete(s_ex) ExercizeSet.delete(s_ex_set)
from django import forms class ExercizeForm(forms.Form): name = forms.CharField() muscle_group = forms.CharField() class ExercizeSetForm(forms.Form): exercize_key = forms.ChoiceField(label='Exercize') weight = forms.FloatField() reps = forms.IntegerField() sets = forms.IntegerField(initial=1) from dal.models import Exercize ExercizeSetForm.base_fields['exercize_key'].choices = [('Exercize:'+ex.get_key(), ex.name) for ex in Exercize.get_all()]