Hi Gregor & others,

I've noticed the https://github.com/idangazit/formrendering and it reminds 
me the approach I'm using for all my django 1.3 projects:

{# forms/fields/as_dl.html #}
<dl> <dt> {{ field.label_tag }}} </dt> <dd> {{ field }}
{% include "forms/fields/errors.html" %} </dd> </dl>

and then:

<form action='' method='POST'> {% csrf_token %} {% include 
'forms/fields/as_dl.html' with field=product_form.title %} {% include 
'forms/fields/as_dl.html' with field=product_form.conditions %}
<input type='submit'> </form>

This can be used in a loop:

{# forms/my_as_ul.html #}
{% include "forms/non_field_errors.html" %} 
<ul>
{% for field in form %} 
<li>{% include 'form/fields/as_dl.html' %}</li> {% endfor %}
</ul>

and then:

{% include 'forms/my_as_ul.html' with form=product_form %}

If individual field should be changed then django-widget-tweaks can be used:

{% load widget_tweaks %}
<form action='' method='POST'> {% csrf_token %} {% include 
'fields/as_dl.html' with field=form.title|attr:"autofocus" %}
{% include 'fields/as_dl.html' with 
field=form.conditions|add_class:"foo"|attr:"type:search" %}
{% include 'forms/buttons/submit.html' with value="Save" %} </form>

This approach does not provide all the sugar from the Idan's and Gregor's 
proposals (namely, it forces developer to list all fields if one field is to 
be tweaked) but it is quite simple, introduces no new concepts and can be 
used in existing django 1.3 projects.

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-developers/-/fAq3shFikDMJ.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to