I'm having some trouble solving a newforms problem that other people
must have run into as well. Feel free to share solutions or
workarounds if any.

Let's say I have a RegistrationForm that is used for registering new
users. It has the usual 'name', 'email', ... etc fields. When a new
user registers, my custom 'clean_email' method is called that checks
if the entered email address is already in use. If it is, this user
has probably already registered, so i raise a validation exception.
All this works as expected for registering new users.

Now I want to provide the possibility for registered users to change
their data. So I create the form instance, passing the user
object's .__dict__ as data (form_for_model is not a viable solution in
my case). The form is rendered with the correct data prefilled and the
user can edit his data. The problem however, is that the emailfield is
validated again, and the validationerror is raised saying that the
email address is already in use. This time around i would need a
different clean_email method.

How do I solve this problem? I could create a subclass of my form that
overrides the clean_email method, but there must be a better way. I
don't think my use case is a once-off either.

What would solve my problem is bound newforms not validating when
rendered unless .is_valid was called or .errors was accessed in the
view. There's probably a downside to this approach that I'm not seeing
though.

Are there previous discussions on this topic that I've missed?

Thanks,
Simon


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to