Dear Django Community,
as a first django project I tried to write a site to manage cooking recipes. My model is quite simple:
* 1 recipe has n steps
* 1 step has a description and n ingredients, each of a certain amount defined by a certain unit
all in all, I have 5 tables (Recipe, Step, Ingredient, Unit, StepIngredient).
After reading through some documentation and trying around a little bit, I got my model and my admin site (I had to install django-nested-inline for the admin site to fit my expectations).
Now I am struggeling with my views. There is a simple index view wich basically lists all recipes:
The hard part is setting up the details view. It is supposed to show the recipes name as a title and then list all the required ingredients and all the required steps. It tried something like:
but it seems I am not allowed to modify the recipes object. Any ideas how to pass all the data which belongs to recipe to the template?
Thank you,
Simon
-- as a first django project I tried to write a site to manage cooking recipes. My model is quite simple:
* 1 recipe has n steps
* 1 step has a description and n ingredients, each of a certain amount defined by a certain unit
all in all, I have 5 tables (Recipe, Step, Ingredient, Unit, StepIngredient).
After reading through some documentation and trying around a little bit, I got my model and my admin site (I had to install django-nested-inline for the admin site to fit my expectations).
Now I am struggeling with my views. There is a simple index view wich basically lists all recipes:
class IndexView(generic.ListView):
context_object_name = 'recipes_list'
def get_queryset(self):
return Recipe.objects.all()
The hard part is setting up the details view. It is supposed to show the recipes name as a title and then list all the required ingredients and all the required steps. It tried something like:
def detail(request, pk):
recipe = Recipe.objects.get(id=pk)
recipe['steps'] = Steps.objects.filter(recipe_id=pk)
template = loader.get_template('recipe/recipe_detail.html')
context = {
'recipe': recipe,
}
return HttpResponse(template.render(context, request))
but it seems I am not allowed to modify the recipes object. Any ideas how to pass all the data which belongs to recipe to the template?
Thank you,
Simon
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/13050a08-1f80-41d0-9739-bf9dae9ef0d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment