Delete Query Not Working

64 views
Skip to first unread message

samurai

unread,
Jul 9, 2014, 4:32:43 AM7/9/14
to web...@googlegroups.com
This is the function for deleting a record from database. 

def pro_del():
        d = request.args
        db(db.products.product_id == d).delete()
        session.flash = "Product Deleted"
        redirect(URL('default','index'))
        #return locals()

The id is successfully getting passed to the function by args(means d is getting its value). I checked it by returning locals.
The redirection is also working fine. Its also flashing the msg. 
Just the query is not working.

Manuele Pesenti

unread,
Jul 9, 2014, 7:02:55 AM7/9/14
to web...@googlegroups.com
Il 09/07/14 10:32, samurai ha scritto:
> def pro_del():
> d = request.args
> db(db.products.product_id == d).delete()
> session.flash = "Product Deleted"
> redirect(URL('default','index'))
> #return locals()
try this:

def pro_del():
d = request.args(0) or redirect(URL('default', 'index'))
db(db.products.product_id == int(d)).delete()
...

cheers

M.
Message has been deleted

Leonel Câmara

unread,
Jul 9, 2014, 9:00:04 AM7/9/14
to web...@googlegroups.com
It should be:
d = request.args(0)

samurai

unread,
Jul 11, 2014, 3:21:14 AM7/11/14
to web...@googlegroups.com
As both Manuele and Leonel said, I changed it to args(0). But no use. It was still not working.

I actually changed a bit and now I am getting 'd' by get.vars.

def pro_del(): 
         d = request.get_vars.d 

         db(db.products.product_id == d).delete() 
         session.flash = "Product Deleted" 
         redirect(URL('default','index')) 
         #return locals()

Now also everything is working fine except the delete query.
Note: I am redirecting and appending the vars by using a javascript function on the view side. If it has to do something with this problem.

lyn2py

unread,
Jul 14, 2014, 7:44:53 AM7/14/14
to web...@googlegroups.com
Did you turn on versioning?

Can you post a traceback?

Shubham Jain

unread,
Jul 15, 2014, 10:05:09 AM7/15/14
to web...@googlegroups.com
No, I hadn''t. But it worked on turning it on. Thanks
But I don't get it. Record versioning just creates an archived db for the modifications done. So how this feature being disabled is restricting me from deleting a record ??

Shubham Jain
3rd Year, Software Engg
Delhi Technological University(Formerly DCE).


--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/7_0Vvdx6Unw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

dlypka

unread,
Jul 17, 2014, 12:06:42 AM7/17/14
to web...@googlegroups.com
you might need to db.commit() after the delete().
versioning might be doing a commit() for you.
Reply all
Reply to author
Forward
0 new messages