2012/4/2 Daniel França <daniel.fra...@gmail.com>
>
> Hello there,
> I'm trying to create an instance for a model after fill a form, but then I 
> got this error message when I click in submit:
>
> int() argument must be a string or a number, not 'Job'
>
> I've tried to debug this, the instance just before the save action has all 
> its properties values as None
>
> here's the code.
> […]
>
> Form:
> class NewJobForm(forms.ModelForm):
>
>     due_date = forms.DateField(widget = widgets.AdminDateWidget())
>
>     class Meta:
>         model = Job
>         exclude = ( 'created_by','date_created')
>
>     def __init__(self, *args, **kwargs):
>         super( NewJobForm, self ).__init__(*args, **kwargs)
>         self.fields["due_date"].widget = widgets.AdminDateWidget()
>
>
>     def save(self, request, commit=True):
>         """
>         Save Job in the DB
>
>         @type commit: boolean
>         @param commit: whereas it is to commit or not
>         """
>         instance = Job(super(NewJobForm, self).save(commit=False))

This line is nonsense. The return value of ModelForm.save() is an
instance, not something which you pass to a constructor to create an
instance. If you replace this line with

         instance = super(NewJobForm, self).save(commit=False)

then your form will work correctly.

Cheers

Tom

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

Reply via email to