Re: Total in a django template

2010-11-08 Thread Gath
Try using custom tags

Create a folder called "templatetags" in your application folder, in
there create two files
 __init__.py
 customtags.py# this will have your custom tags/filters, please
note it can be any name.

Open your customtags.py file and drop the following lines and save.

from django.template import Library

register = Library()

@register.filter
def running_total(fine_list):
return sum(d.get('fine_sum') for d in fine_list

In your template call the customtags file like this

{% load customtags %}

i guess by this time you have a list of dict that you passed from your
view lets say its called "fines"

{% for fine in fines %}
  Display your fine items inside this loop
{% endfor %}

outside the loop call the customtag like this

 {{ fines.list|running_total }} 

It works for me.

Paul.



On Nov 9, 12:09 am, Knut Ivar Nesheim  wrote:
> You need to sum the fines before you enter the templates.
>
> This can be done either in your view like this:
>     total_fines = sum([item.fine for item in items])
>
> Or you can do it in the db using the 'Sum' aggregate, 
> seehttp://docs.djangoproject.com/en/dev/ref/models/querysets/#sum
>
> Regards
> Knut
>
> On Sun, Nov 7, 2010 at 12:32 AM, Michael Sprayberry
>
>
>
>
>
>
>
>  wrote:
>
> > Hello,
> >     I am not sure if this is what you are looking for but you can use a 
> > forloop.counter (index to 1) or a forloop.counter0 (index at 0) from within 
> > the template {% for loop %}
>
> > Michael
>
> > Hi,
> > In a django template I have a for loop that display (item, fine). I
> > would like to compute the total fine value at the end of the for loop.
> > Is it possible to compute the total in the template? How can I do it
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Re: Total in a django template

2010-11-08 Thread Knut Ivar Nesheim
You need to sum the fines before you enter the templates.

This can be done either in your view like this:
total_fines = sum([item.fine for item in items])

Or you can do it in the db using the 'Sum' aggregate, see
http://docs.djangoproject.com/en/dev/ref/models/querysets/#sum

Regards
Knut

On Sun, Nov 7, 2010 at 12:32 AM, Michael Sprayberry
 wrote:
>
> Hello,
>     I am not sure if this is what you are looking for but you can use a 
> forloop.counter (index to 1) or a forloop.counter0 (index at 0) from within 
> the template {% for loop %}
>
>
> Michael
>
> Hi,
> In a django template I have a for loop that display (item, fine). I
> would like to compute the total fine value at the end of the for loop.
> Is it possible to compute the total in the template? How can I do it
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Re: Total in a django template

2010-11-06 Thread Michael Sprayberry
Hello, 
    I am not sure if this is what you are looking for but you can use a 
forloop.counter (index to 1) or a forloop.counter0 (index at 0) from within the 
template {% for loop %}
 
 
Michael



Hi,
In a django template I have a for loop that display (item, fine). I
would like to compute the total fine value at the end of the for loop.
Is it possible to compute the total in the template? How can I do it

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.




  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Total in a django template

2010-11-06 Thread Akn
Hi,
In a django template I have a for loop that display (item, fine). I
would like to compute the total fine value at the end of the for loop.
Is it possible to compute the total in the template? How can I do it

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.