You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Django developers
There's numerous time where I found myself wishing for type casting
filters in templates..
For example, the following won't work because one is a string and the
other is an integer:
{% if request.GET.year == object.date.year %}
...
{% endif %}
So when I need to compare a string with an int without having to write
custom filters, I use this hack:
{% if request.GET.year == object.date.year|slugify %}
...
{% endif %}
While it works, it ain't pretty.
It would be nice if we could simply do this:
{% if request.GET.year == object.date.year|string %}
...
{% endif %}
Or this:
{% if request.GET.year|int == object.date.year %}
...
{% endif %}
Am I the only one who gets in such situations ? Is there an interest
for such filters ?
If so I might propose a patch..
Regards
Florian Apolloner
unread,
Oct 3, 2011, 12:18:18 PM10/3/11
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django-d...@googlegroups.com
Hi,
personally I am -1 on that, for the following reasons:
This can be done in an external library
You can't support every possibility, you want a string/int filter, I want a blableblub/younameit type conversion
playing with request.GET.* in templates is probably something you shouldn't do anyways (and other objects coming from the views should have correct types)…