Tuesday, June 26, 2012

How to Query objects.filter ForeignKey

I'm trying to pass a objects.filter dictionary to HttpResponse. The problem is I have 2 models: InfoBox and InfoDetail. InfoDetail is linked to InfoBox by models.ForeignKey(InfoBox). What I want to do is filter by title which lives in the InfoBox model. I performed infobox = InfoDetail.objects.filter(title=info_title), but it returns an error cus 'title' doesn't live in InfoDetail.

How can i grab and filter it by title and pass {'infobox': infobox} in HttpResponse when HttpRequest is called?

Here's models: http://paste.ubuntu.com/1061144/
Here's views: http://paste.ubuntu.com/1061146/

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/Y4H1cgbG1yAJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment