Re: range-like template tag?

2008-12-08 Thread Berco Beute

Ah! Of course, why didn't I think of that! Works like a charm.

Thx!
2B

On Dec 8, 7:23 pm, Adi Sieker <[EMAIL PROTECTED]> wrote:
> Couldn't you add a method get_range() (or whatever name makes sense in  
> your context)
> to the class the object is an instqnce of.
> The method would look something like this:
>      def get_range(self):
>          return range(self.someInt)
>
> in your template you could then do:
>      {% for i in object.get_range %}
>
> adi
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: range-like template tag?

2008-12-08 Thread Adi Sieker

Hi,

On 08.12.2008, at 17:30, Berco Beute wrote:

>
> The 'someInt' is an attribute of an object I pass to the template. It
> varies with each object. I could of course make a dictionary with the
> object and a list of the integers but it would be handy to solve it in
> the template (although you may argue that such functionality should
> stay out of the view)

Couldn't you add a method get_range() (or whatever name makes sense in  
your context)
to the class the object is an instqnce of.
The method would look something like this:
 def get_range(self):
 return range(self.someInt)

in your template you could then do:
 {% for i in object.get_range %}


adi

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: range-like template tag?

2008-12-08 Thread Berco Beute

The 'someInt' is an attribute of an object I pass to the template. It
varies with each object. I could of course make a dictionary with the
object and a list of the integers but it would be handy to solve it in
the template (although you may argue that such functionality should
stay out of the view)

2B

On Dec 8, 5:14 am, Jeff FW <[EMAIL PROTECTED]> wrote:
> You could write a very simple filter to do this.  Something like
> (untested):
>
> def range(top):
>     return xrange(0, top)
>
> then use {% for i in someInt|range %}
>
> I think it would still be better to pass it in the context--why can't
> you do that?
>
> -Jeff
>
> On Dec 7, 5:12 pm, Berco Beute <[EMAIL PROTECTED]> wrote:
>
> > Is there a template tag to turn an int into a sequence (like 'range')?
> > What I want to do is populate a select widget with the numbers up to
> > the int, like:
>
> > ==
> > 
> >     {% for i in someInt.range %}
> >         {{i}}
> >     {% endfor %}
> > 
> > ==
>
> > Passing the sequence through the context is not an option in my
> > particular case.
>
> > 2B
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: range-like template tag?

2008-12-07 Thread Jeff FW

You could write a very simple filter to do this.  Something like
(untested):

def range(top):
return xrange(0, top)

then use {% for i in someInt|range %}

I think it would still be better to pass it in the context--why can't
you do that?

-Jeff

On Dec 7, 5:12 pm, Berco Beute <[EMAIL PROTECTED]> wrote:
> Is there a template tag to turn an int into a sequence (like 'range')?
> What I want to do is populate a select widget with the numbers up to
> the int, like:
>
> ==
> 
>     {% for i in someInt.range %}
>         {{i}}
>     {% endfor %}
> 
> ==
>
> Passing the sequence through the context is not an option in my
> particular case.
>
> 2B
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



range-like template tag?

2008-12-07 Thread Berco Beute

Is there a template tag to turn an int into a sequence (like 'range')?
What I want to do is populate a select widget with the numbers up to
the int, like:

==

{% for i in someInt.range %}
{{i}}
{% endfor %}

==

Passing the sequence through the context is not an option in my
particular case.

2B
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---