On Sun, Feb 28, 2016 at 11:47 AM, Rahul Gandhi <rahul.rahulgags@gmail.com> wrote:
You could do something like this:
def detail(request, pk):
recipe = Recipe.objects.get(id=pk)
steps = Steps.objects.filter(recipe_id=pk)
template = loader.get_template('recipe/recipe_detail.html')
context = {
'recipe': recipe,
'steps': steps
}
return HttpResponse(template.render(context, request))
And make appropriate changes to your template.
There's really no point is doing this. Within the template, {{ recipe.steps }} should already contain everything that {{ steps }} would contain in this instance. All you've done is created extra work for the ORM and added complication to the code.
Your context should only contain { 'recipe': recipe } at this point. Frankly, I'm not sure if it even needs that if you are using the built-in class-based views such as DetailView.
-James
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/CA%2Be%2BciX0hufY9%2ByfGpM12%3DCzQK7q2AfDTxikJupppoTeXk%2BdiA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment