ModelForm validation in 1.2.3

2010-12-30 Thread Burhan
Hello:

  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-us...@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.



Re: ModelForm validation in 1.2.3

2010-12-30 Thread Ferran
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

On 30/12/10 17:25, Burhan wrote:
>  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?

http://docs.python.org/tutorial/errors.html
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBCAAGBQJNHLQCAAoJEAWOKfEESaOw/KkQAJpykIq4NuWT2pFlzT/jg2Ck
ZLPnKTABp7JmvDdNflreKhKDKmhMSmYTu9/ThF8RtGgtstq5oUtdhZmKoRnpnuWe
GHFPPidSBD9NOs1MFgj1+8kkvcTFLE6kPRupfNN9nJKFm4gZ8dpV602WOJWlK1dJ
4ViK5fFU4AwOoGpqZrmMG6J8bzOKs6U6rNJP4YLSvMyRyEOj5qVwAo9x4V+NpgHg
5NiWADvWnwISc7QdB84ViYsmF3ocIIZnzAgLbRa7kej/8NQ/ikndc7gAvjpseJi7
R3GiaW816m/PElkXlbiszKxjJQSYP9uDfzURJ9oJyU5LNa1cNkr1RrWAtlh/j5RI
mCwyq7I7MbFodsJe7ZGpUzspZfyk9lxSYAfaVZcE9v9fVJc1y6JbW0KyMl3MJyZG
K0x+PA+X03gEDnr9fso3cijBc1gz3sVGyj3C5rOgaCnlasRQzbjcjOaIx8GpUTgU
4OgP5k/Agz6eYr08JES1cvOeug7TYGY4x84MRwe++RgaOhf/1W7v4Hrvm22hBGcA
ivBr0xt0rdzCQKeX2JriDMcqWE99KTEEqqWX4bA1l47UiaWg16wvyoxgexQT7Y0O
larKwMr/5G9+2fQOoYzHL9EcDmzzWJHNjrIZmjrIMv+6fQ5b30aTIh+qI8yvg2vw
roI7MOFS6TYefl0QhP8R
=jP4n
-END PGP SIGNATURE-

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Re: ModelForm validation in 1.2.3

2010-12-30 Thread Burhan
The question is how do I get the modelform to only check for form
validity, and not model validity (like it did before). I don't see
what your link has to do with that.

On Dec 30, 7:32 pm, Ferran  wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA256
>
> On 30/12/10 17:25, Burhan wrote:
>
> >  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?
>
> http://docs.python.org/tutorial/errors.html
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.11 (GNU/Linux)
> Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org/
>
> iQIcBAEBCAAGBQJNHLQCAAoJEAWOKfEESaOw/KkQAJpykIq4NuWT2pFlzT/jg2Ck
> ZLPnKTABp7JmvDdNflreKhKDKmhMSmYTu9/ThF8RtGgtstq5oUtdhZmKoRnpnuWe
> GHFPPidSBD9NOs1MFgj1+8kkvcTFLE6kPRupfNN9nJKFm4gZ8dpV602WOJWlK1dJ
> 4ViK5fFU4AwOoGpqZrmMG6J8bzOKs6U6rNJP4YLSvMyRyEOj5qVwAo9x4V+NpgHg
> 5NiWADvWnwISc7QdB84ViYsmF3ocIIZnzAgLbRa7kej/8NQ/ikndc7gAvjpseJi7
> R3GiaW816m/PElkXlbiszKxjJQSYP9uDfzURJ9oJyU5LNa1cNkr1RrWAtlh/j5RI
> mCwyq7I7MbFodsJe7ZGpUzspZfyk9lxSYAfaVZcE9v9fVJc1y6JbW0KyMl3MJyZG
> K0x+PA+X03gEDnr9fso3cijBc1gz3sVGyj3C5rOgaCnlasRQzbjcjOaIx8GpUTgU
> 4OgP5k/Agz6eYr08JES1cvOeug7TYGY4x84MRwe++RgaOhf/1W7v4Hrvm22hBGcA
> ivBr0xt0rdzCQKeX2JriDMcqWE99KTEEqqWX4bA1l47UiaWg16wvyoxgexQT7Y0O
> larKwMr/5G9+2fQOoYzHL9EcDmzzWJHNjrIZmjrIMv+6fQ5b30aTIh+qI8yvg2vw
> roI7MOFS6TYefl0QhP8R
> =jP4n
> -END PGP SIGNATURE-

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.