Created
January 2, 2013 19:50
-
-
Save thebookworm101/4437360 to your computer and use it in GitHub Desktop.
error while saving a form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
####### My form isnt getting saved because of this error: iv marked line 19 in the view is line 26 in this gist | |
TypeError at /job/add/article/ | |
save() takes at least 2 arguments (1 given) | |
Request Method: POST | |
Request URL: http://localhost:8000/job/add/article/ | |
Django Version: 1.4.3 | |
Exception Type: TypeError | |
Exception Value: | |
save() takes at least 2 arguments (1 given) | |
Exception Location: /views.py in add_job, line 19 | |
####### here is the view: | |
@login_required | |
def add_job(request): | |
form = JobForm(request.POST or None) | |
if form.is_valid(): | |
article = form.save(commit=False) #####<<<== this is line 19 in the view file. | |
article.author = request.user | |
article.save(request.user) | |
msg = "Job saved successfully" | |
messages.success(request, msg, fail_silently=True) | |
return redirect(article) | |
return render_to_response('job/job_form.html', | |
{ 'form': form }, | |
context_instance=RequestContext(request)) | |
### the definition of Jobform in turn is : | |
class JobForm(forms.ModelForm): | |
""" this handles the start_time and end_time defaults""" | |
class Meta: | |
exclude = ['slug','author',] | |
model = Job | |
def __init__(self, *args, **kw): | |
super(JobForm,self).__init__( *args, **kw) | |
def save(self,user, *args, **kw): | |
instance = super(JobForm,self).save(commit=False) | |
#last_entry = Job.objects.filter(user__id=user.id).order_by('-id')[0] | |
last_entry = Job.objects.filter(user=user).aggregate(max_end_time=models.Max('end_time'))['max_end_time'] | |
if last_entry: | |
instance.start_time = last_entry.end_time | |
else: | |
# this is the very first record do something | |
pass | |
instance.save() | |
return instance | |
############## what gives? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment