On 2 sep, 20:22, Matt Berg <[EMAIL PROTECTED]> wrote:
> Sorry.
>
> Yes, in the template I do a loop...
>
> for crop in crops
Where do "crops" come from ? In your above code, you only returned the
ci dict, no t crops.
> In the view, I make an array ci (cropinfo).
It's actually a dict, not an array.
> Each ci I append a new
> dict object (cd) which is associated with the crop id.
>
> In the template, I just want to loop through the crops
How do you make these crops available to your template ?
> and then
> display items in the embedded dict that are tied to the crop.id.
It would be simpler to just attach each 'cd' dict to your crop objects
in the view, then return the list of crops, ie:
def crop_info(season,crops):
hectares = 0
for c in crops:
hectares += c.hectares
cd = {}
cd['dap_kg_dollar'] = (season.DAP_local_fiftykg_price /
season.forex_input) / 50
cd['urea_kg_dollar'] = (season.urea_local_fiftykg_price /
season.forex_input) / 50
cd['seed_local_dollar'] = c.local_seed_price /
season.forex_input
cd['seed_improved_dollar'] = c.improved_seed_price /
season.forex_input
cd['total'] = (c.seed * cd['seed_improved_dollar']) +
(cd['urea_kg_dollar'] * c.urea)
c.crop_info = cd
return crops
Then in your template:
{% for crop in crops %}
{{crop.id}} : {{ crop.crop_info.total }}
{% endfor %}
HTH
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---