On Sat, 2008-04-05 at 19:34 -0700, Julien wrote:
> Hi,
> 
> I'm using templates to customize the way my forms are displayed. I'd
> like to display fields differently depending on their type.
> 
> In python code I can do:
> 
> type = field.field.widget.__class__.__name__
> (considering the field is an instance of
> django.newforms.forms.BoundField)
> 
> However, I can't seem to find how to access a field's type from within
> a template. The following won't work because you're not allowed to
> have attribute starting with underscore in templates:
> 
> This field's type is: {{ field.field.widget.__class__.__name__ }}
> 
> Bizarrely, when inspecting the python code, the field's widget object
> has a 'type' attribute, but I can't access with:
> field.field.widget.type.

Widget classes don't have a type attribute. It's not in the code. I
think you're misinterpreting your output somehow here.

> Do you have an idea how I can achieve that?

This sounds very close to Programming In Templates(tm), so not something
that Django is going to support out of the box. You could write a filter
that returns the name of the widget class. Or, if you just care about
the type at an HTML level, use the input_type attribute on widgets,
which is the type attribute passed to the input element in HTML.

Regards,
Malcolm

-- 
How many of you believe in telekinesis? Raise my hand... 
http://www.pointy-stick.com/blog/


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

Reply via email to