Friday, June 10, 2011

Re: Help with custom model method for query

On 10 juin, 17:23, Chris McComas <mccomas.ch...@gmail.com> wrote:
> Sorry for the confusion, this is what I am trying to achieve. It's the
> FeedType and then FeedItems whose feed (fk) has a (fk) to FeedType.
>
> The HTML would be:
>
> {% for feed_type in FeedType %}
>         <h1>{{ feed_type.name</h1>
>         <ul>
>                 {% for FeedItem in Feed in FeedType %}
>                         <li>{{ feeditem.title }}</li>
>         </ul>
> {% endfor %}

Ok.

Then you need to correct your view:


# views.py

def news(request, city_id):
city = get_object_or_404(City, pk=city_id)
feeditems =
FeedItem.objects.filter(feed__city=city).select_related(depth=2)
return render_to_response(
"path/to/template.html",
dict(city=city, feeditems=feeditems)
)

And then in your template:

{% regroup feeditems by feed_type as feeditems_list %}
<ul>
{% for feed_type in feeditems_list %}
<li>
{{ feed_type.grouper }}
<ul>
{% for entry in feed_type.list %}
<li>{{ entry.title }}</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>

Obviously untested code, but this should work or, at least, get you
started.

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate