On Fri, 2009-03-20 at 23:53 -0700, andrew wrote:
> Hi ,all
> 
>    I encounter a issue lasting 3 days, any help will be highly
> appreciate.
> 
> view:
>      market_volumn={}
>      for m in marketTypeList:
>          market_volumn[m]=MarketVolumn.objects.filter
> (marketType=m).order_by('week')
>      print market_volumn

Not directly related to your question, but just "by the way...", this
executes one SQL query per element in marketTypeList. You can do the
same thing with only one query:

        queryset = MarketVolumn.objects. \
                   filter(marketType__in=marketTypeList). \
                   order_by("week")
        market_volumn = dict([(o.marketType, o) for o in queryset])
        
Anyway, back to your question...

> 
> in the console ,the print result like this:
>      {<MarketType:1>:[<MarketVolumn: MarketVolumn
> object>,<MarketVolumn: MarketVolumn object>],<MarketType:2>:
> [<MarketVolumn: MarketVolumn object>,<MarketVolumn: MarketVolumn
> object>]}
> 
> how can I output corresponding in the template?  I want result like
> this:
> 
> MarketType1
> MarketVolumn11,MarketVolumn12,MarketVolumn13
> MarketType2
> MarketVolumn21,MarketVolumn22,MarketVolumn23

Pass the market_volumn dictionary to the template, by putting something
like this at the end of your view:

        return render_to_response("my_template.html", {"market_volumn": 
market_volumn}
        
Then, in your template:

        {% for market_type,volumn in market_volumn.items %}
           {{ market_type }}
           {{ volumn|join:", " }}
        {% endfor %}

Is that what you're after?
        
Even if that's not exactly what you want, that should give you a few
clues on things to look for. Have a quick read through the documentation
for the built-in template tags and filters to see if there are other
things like "join" that can help you out here.

Regards,
Malcolm


--~--~---------~--~----~------------~-------~--~----~
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