Tuesday, June 26, 2012

Re: How to Query objects.filter ForeignKey

That worked like a charm! I read about the double underscore but didn't think much about it when it crossed my mind. I've been grinding on this for the whole day. My eyes... =)

On Tuesday, June 26, 2012 1:04:40 PM UTC-7, Kurtis wrote:
 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?

If you want to filter by a certain title, then you'd do something like this:

InfoDetail.objects.filter(infobox__title="Some Title") 

That would return all InfoDetail objects whose related InfoBox has a specific title.

If that doesn't help solve your problem, let me know what else you're stuck on :)

--
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/-/5fEndcSA6KIJ.
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