Hello
I am not sure if title describes what i want accurately. What i want is to achieve something like that: http://stackoverflow.com/questions/1405587/django-add-remove-form-without-multiple-submit/1406819#1406819.
But i have not list of items i have formset and forms. The form of this formset does contain information i could use for creating link like that {% url 'item_edit' item.id %}. The problem is that it is a value of an hidden field. Here (http://docs.djangoproject.com/en/dev/topics/forms/#looping-over-the-form-s-fields) you have a list of options how to use fields of a form in a template, but none of them is {{ field.value }}. If i tried that, then it just failed silently.
Anyway. to the code. What i have in template is:
<form enctype="multipart/form-data" method="post" action="/list/edit/{{ list.id }}/">
<table>
{{ form.as_table }}
{{ formset.management_form }}
{% for form in formset.forms %}
{% if forloop.first %}
<tr>
{% for field in form.visible_fields %}
<td>{{ field.label }}</td>
{% endfor %}
</tr>
{% endif %}
<tr>
{% for field in form.visible_fields %}
{% if not forloop.last %}
<td>{{ field }}</td>
{% else %}
<td>{{ field }}
{% endif %}
{% endfor %}
{% for field in form.hidden_fields %}
{% if not forloop.last %}
{{ field }}
{% else %}
{{ field }}</td>
{% endif %}
{% endfor %}
</tr>
{% endfor %}
<tr><td><input type="submit" value="Submit"></td><td colspan="4"> </td></tr>
</table>
</form>
And this gives me inline form rows like this:
<tr>
<td><input type="text" maxlength="200" value="test2" name="shoppinglistitem_set-0-itemname" id="id_shoppinglistitem_set-0-itemname"/></td>
<td><input type="text" maxlength="200" value="http://www.xxx.ee" name="shoppinglistitem_set-0-link" id="id_shoppinglistitem_set-0-link"/></td>
<td><input type="text" maxlength="100" value="eepöäsdöäfsdfd" name="shoppinglistitem_set-0-store" id="id_shoppinglistitem_set-0-store"/></td>
<td><input type="text" id="id_shoppinglistitem_set-0-price" value="22134" name="shoppinglistitem_set-0-price"/></td>
<td><input type="checkbox" id="id_shoppinglistitem_set-0-DELETE" name="shoppinglistitem_set-0-DELETE"/><input type="hidden" id="id_shoppinglistitem_set-0-list" value="1" name="shoppinglistitem_set-0-list"/><input type="hidden" id="id_shoppinglistitem_set-0-listitem_ptr" value="5" name="shoppinglistitem_set-0-listitem_ptr"/></td>
</tr>
and i am looking for some way to add link like this
<a href={% url 'remove_list_item' item.id %}>REmove</a>
or just
<a href="http://localhost/list/removeitem/{{ id }}">REmove</a>
Urlconf for this view is:
url(r'^removeitem/(?P<lisitem_id>\d+)/$', 'remove_list_item', name='remove_list_item')
So is there some easy way to get that id of the item(object) from the form? Do i have to create some kind of widget for that remove link instead?
Alan.