tags:

views:

753

answers:

2

I want a simple edit / remove form in Django.

I want it to look like:

Item A   edit  /   remove
Item B   edit  /   remove
Item C   edit  /   remove

I want to the edit and remove "buttons" to be hyperlinks, or at least look like them.

Is there an easy way without multiple submit buttons (and without violating the whole POST/GET thing?)

A: 

You would probably do better not using a Form to achieve this, as there are (from what you've described) no form elements required.

Instead you could have a setup in which your urls.py has 2 urls,

url(r'^app/edit/(?P<id>.*)$', edit_view, name='item_edit'),
url(r'^app/remove/(?P<id>.*)$', remove_view, name='item_remove'),

And the interface you described above is generated by a template which simply uses {% url %} tag to make hyperlinks to those addresses. Say, for example, you are passing the variable 'items' in your context, you template code would look like this

<table>
{% for item in items %}
    <tr>
      <td>{{item.name}}</td>
      <td>{% url 'item_edit' item.id %}</td>
      <td>{% url 'item_remove' item.id %}</td>
    </tr>
{% endfor %}
</table>

...or something to all that effect...

T. Stone
thanks. I've implemented this. Although it uses GET, and hence breaking the standards a bit (using a GET to do a delete from a db). How can you follow the standards when it is so difficult? (without coding a multi submit form with CSS controlled submit buttons)...
geejay