On Sunday, 22 January 2012 10:42:53 UTC, Johan wrote:
>
> Hi I have a form that has a required email field. This due to the fact
> that the model requires an email. However, I don't display the email
> field on the form. So when the post gets back into my view the email
> field is empty. I then thought I would do the following just before
> the form.is_valid() :
>
> form = students.forms.StudentForm(request.POST)
> form.instance.email=user.email
>
> User is a session variable which contains the correct email for the
> session. The above code however still fail with is_valid. I even
> changed the forms clean_email() to return the correct email. But, I
> still get 'This field is required'.
>
> Any help would be appreciated.
>
>
If you don't want the email field to be displayed or validated, you should
exclude it from the form by using the `exclude` tuple in the form's Meta
class. Then, on saving, you can do:
student = form.save(commit=False)
student.email = user.email
student.save()
--
DR.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/django-users/-/N3llNx-6gdcJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.