Awesome, this is very helpful. Thanks!
On Jun 25, 5:09 am, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > On Wed, 2008-06-25 at 00:42 -0700, bruno desthuilliers wrote: > > On 25 juin, 01:03, davenaff <[EMAIL PROTECTED]> wrote: > > > In a template, I'm using the equivalent of: > > > {% for field in form %} > > > {{ field.label_tag }}{{field}} > > > {% endfor %} > > > > However, the labels of my hidden fields appear. Is there an easy way > > > to test if the field is using the HiddenInput widget (or an alternate > > > solution)? > > > What about "field.is_hidden" ?-) > > I've found myself recently adding a method to my form classes (I use a > common base class) so that I can iterate over only the visible fields: > > def visible_fields(self): > """ > Returns a list of BoundField objects that are not marked as > hidden. > """ > return [field for field in self if not field.is_hidden] > > Then, where you've written {% for field in form %}, I write > > {% for field in form.visible_fields %} > > I also have a hidden_fields() method (which is almost identical to the > above) so that I can then include all the hidden fields in the final > form as well. I've used this on two recent projects I've worked on where > I have some custom form layout requirements and want to do it in the > template, rather than via a Python method. > > Regards, > Malcolm --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---