Tuesday, August 30, 2011

Unable To Delete Records

Hi All...

I have created a small application where in i am inserting and
deleting records. I am able to delete a single record however when a
select all or more then one record it deletes the last record only.. I
tried a lot but failed please help I am wring the Code and the Console
output here....


===========================================
my function to delete a medecine from its table in views.py
===========================================

def delete_medecine(request,medecine={}):
print "------>>",request.POST
list = []
for i in request.POST['del_id']:
m = Medecine.objects.get(id = i)
m.delete()
return HttpResponseRedirect('/medecine')

==============================================
my template file


<form action="/delete_medecine/" name = "medecines" method = "POST">
<table cellspacing="0" cellpadding="0" border="0"><!-- Table -->

<thead>
<tr>
<th><input type="checkbox" class="checkall" /></th>
<th>SNo.</th>
<th>Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Exp. Date</th>
<th>Description</th>
</tr>
</thead>

<tbody>
{% for single in medecine_obj%}
<tr>
<td><input type="checkbox" value="{{single.id}}" name
= "del_id" /></td>
<td>{{single.id}}</td>
<td>{{single.name}}</td>
<td>{{single.price}}</td>
<td>{{single.exp_date}}</td>
<td>{{single.discription}}</td>
<td><a href="#"><img src="/login/media/assets/
action_check.png" alt="Check" /></a><a href="/delete_medecine/"><img
src="/login/media/assets/action_delete.png" alt="Delete" /></a><a
href="#"><img src="/login/media/assets/letter.png" alt="Letter" /></
a></td>
</tr>
{%endfor%}
</tbody>
<a href="/medecine_form/"><input type = "button" name = "add"
value = " Add Record " alt="Add" /></a>
<input type = "submit" name = "delete" value = "Delete Records"
alt="Delete" />

</table>
</form>

===========================
My Console
===========================

/usr/local/lib/python2.6/dist-packages/django/middleware/csrf.py:262:
DeprecationWarning: CsrfResponseMiddleware and CsrfMiddleware are
deprecated; use CsrfViewMiddleware and the template tag instead (see
CSRF documentation).
DeprecationWarning
================================== <QueryDict:
{u'csrfmiddlewaretoken': [u'fea796e4bc7836bb8584140b71a0afcc'],
u'del_id': [u'1', u'2', u'8'], u'delete': [u'Delete Records']}>
===== 8
[30/Aug/2011 06:04:56] "POST /delete_medecine/ HTTP/1.1" 302 0

==============


Please help

--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment