On Sat, May 16, 2009 at 11:07 AM, pradyumna <joshi.pradyu...@gmail.com>wrote:

>
> I am a newbie to Django.. I am wondering why I am getting 'Caught an
> exception while rendering: 'Car' object is not iterable?
>
> As per my understanding,  in the template, if statement should not be
> true and else portion should be executed.
>
> Can anybody help me on this?
>
>
> View:
> --------
>
> def v_list(request,car_number=None):
>
>    try:
>        if car_number!=None:
>            car_list=Car.objects.get(id=car_number)
>        else:
>            car_list=Car.objects.order_by('name')
>
>    except:
>        raise Http404('Requested Info. not found')
>     cars_render=RequestContext(request,{'car_list':car_list})
>    return render_to_response('cars.html',cars_render)
>
> Template:
> -------------
>   {% if car_list %}
>            {% for car in car_list %}
>                 {{car.id}} ,{{car.name}}
>            {% endfor %}
>
>    {%else%}
>            {{car_list.name}}
>    {% endif %}
>
> >
>
Using get() returns a single object, whereas using others methods returns a
QuerySet.  A single object is just that, one object, whereas a QuerySet is a
group of objects, so you need to know which one you have to know how to work
with it.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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

Reply via email to