LS. I'm building a nut mix recept database:
class Ingredient(models.Model): naam = models.CharField(max_length=30) class MaatEenheid(models.Model): naam = models.CharField(max_length=30) class Recept(models.Model): naam = models.CharField(max_length=30) hoeveelheid = models.PositiveIntegerField(max_length=4) maat = models.ForeignKey(MaatEenheid) ingredient = models.ManyToManyField(Ingredient, through='Verhouding') bereiding = models.TextField(max_length=500) class Verhouding(models.Model): ingredient = models.ForeignKey(Ingredient) recept = models.ForeignKey(Recept) maat = models.ForeignKey(MaatEenheid) hoeveelheid = models.PositiveIntegerField(max_length=4) volgorde = models.PositiveIntegerField(max_length=2) Now I want to create a preparation page with following data: -Recepy name, (Recept.naam) -Way of preparation (Recept.bereiding) -amount produced by recept (Recept.hoeveelheid) -Measuring unit of amount (Recept.maat) and a list of ingredients: -order of addition (Verhouding.volgorde) -ingredient name (Verhouding.ingredient) -ingredient amount (Verhouding.hoeveelheid) -Measuring unit of amount (Recept.maat) Selecting the data for te recept is no problem, However getting the ingredient data is proving a pain. My views.py: def bereiding(request, gevraagd_recept): lijst_recept = \ Recept.objects.select_related().filter( naam = gevraagd_recept ) lijst_ingredient = \ Verhouding.objects.select_related('ingredient').filter( recept = lijst_recept[0] ) naam_sjabloon = 'template_receptvieuw' return render_to_response(naam_sjabloon + '.sbl', \ { 'receptregel': lijst_recept, \ 'ingredientregel': lijst_ingredient } ) Lijst Recept correctly contains all recept-specific data from the Recept model. ingredients are returned as a manyrelatedmanager. This manyrelatedmanager _only_ returns ingredient names both when executed interactively and when implemented in a view/template {% for regel in receptregel %} {{regel.naam}} {{regel.hoeveelheid}} {{regel.maat}} {% for ingredient in regel.ingredient.all %} {{ingredient.volgorde}}: {{ingredient.naam}} {{ingredient.hoeveelheid}} {{ingredient.maat}} <br /> {% endfor %} {% endfor %} Ingredient amounts, measures and orders aren't returned. When I use the manytomany table (lijst_ingredient) I _do_ get the ingredient amounts, measures and orders but he ingredient names are lost! {% for ingredient_item in ingredientregel %} {{ingredient_item.volgorde}}: {{ingredient_item.naam}} {{ingredient_item.hoeveelheid}} {{ingredient_item.maat}} <br /> {% endfor %} What am i doing wrong?? Can I combine the ingredient names from lijst_recept with the ingredient data from lijst_recept? Regards, Marout --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---