In 1.2 ModelForm validation was changed so that not only does it
check the form validation, but it does validation of the model as
well.
I have a model that has custom validation for one of its fields,
which should be unique in the table. Now I have a front end form,
created by ModelForm for this model.
I want do to the following:
1. Check if the fields are correctly filled in, as per the custom
validator written for this model.
2. If an entry already exists for using the 'unique' field, return
that object.
3. If and entry doesn't exist, create a new object.
In the old django, before this change, I could easily do it:
if request.method = 'POST':
form = CustomerForm(request.POST)
if form.is_clean():
try:
customer =
Customer.objects.get(email=form.cleaned_data['email'])
except Customer.DoesNotExist:
customer = form.save()
In 1.2.3, this logic always fails because "is_clean()" fails if an
existing customer enter's their email address. How can I do the same
using django 1.2.3?
Thanks.
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment