avorum
avorum

Reputation: 2293

How to use delete() for a model in django

I'm trying to delete a Job object from my database and I keep getting the error:

TypeError at /minion/deleteJob/

deleteJob() takes exactly 2 arguments (1 given)

Request Method:     GET
Request URL:    http://127.0.0.1:8000/minion/deleteJob/
Django Version:     1.5.1
Exception Type:     TypeError
Exception Value:    

deleteJob() takes exactly 2 arguments (1 given)

Exception Location:     /usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py in get_response, line 115
Python Executable:  /usr/bin/python
Python Version:     2.7.4
Python Path:    

            ['/home/jgreen/MinionDjangoApp/minion',
             '/usr/lib/python2.7',
             '/usr/lib/python2.7/plat-i386-linux-gnu',
             '/usr/lib/python2.7/lib-tk',
             '/usr/lib/python2.7/lib-old',
             '/usr/lib/python2.7/lib-dynload',
             '/usr/local/lib/python2.7/dist-packages',
             '/usr/lib/python2.7/dist-packages',
             '/usr/lib/python2.7/dist-packages/PILcompat',
             '/usr/lib/python2.7/dist-packages/gtk-2.0',
             '/usr/lib/python2.7/dist-packages/ubuntu-sso-client',
             '/usr/lib/python2.7/dist-packages/ubuntuone-client',
             '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel',
             '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol']

Server time:    Mon, 17 Jun 2013 09:34:21 -0500
Traceback Switch to copy-and-paste view

/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py in get_response

                            response = callback(request, *callback_args, **callback_kwargs)

    ...
▶ Local vars

Request information
GET

No GET data
POST

No POST data
FILES

And Here's the code I'm using to try and delete the Job:

#deletes the selected job from the database
def deleteJob(request, name):
    j = Job.objects.get(pk=3)
    Job.objects.filter(name=name).delete()
    return render_to_response('Minion/detail')

If anyone knows what is causing this error that seems to be originating in the python libraries I'd be very grateful.

EDIT: urls.py

from django.conf.urls import patterns, include, url
from django.views.generic import DetailView, ListView
from django.conf.urls.defaults import *
from Minion.models import Job

urlpatterns = patterns('Minion.views',
    # URLs for the MinionUI app
    url(r'^$', 'home'),
    url(r'^index/$', 'detail'),
    url(r'^add/$', 'add'),
    url(r'^output/$', 'output'),
    url(r'^cal/$', 'calendarTest'),
    url(r'^addJobData/$', 'addJobData'),
    url(r'^deleteJob/$', 'deleteJob'),
)

For the record, I don't know regex very well, so bear with me if there are obvious mistakes here.

Upvotes: 0

Views: 116

Answers (1)

Silwest
Silwest

Reputation: 1620

Bad url in url.py

It should looks like this:

(r'^/minion/deleteJob/(\w+)/$', 'deleteJob'),

or if you have also numbers:

(r'^/minion/deleteJob/([a-zA-Z0-9\-\s]+)/$', 'deleteJob'),

Upvotes: 1

Related Questions