thanks very much.
it seems self.instance always exists but its pk(id) is None when it's an add
and not None when it's modification.
----- Original Message -----
From: "Daniel Roseman" <dan...@roseman.org.uk>
To: "Django users" <django-users@googlegroups.com>
Sent: Monday, January 11, 2010 9:27 PM
Subject: Re: Form Validation in Admin
On Jan 11, 3:24 am, "Sasuke" <zhouj...@gmail.com> wrote:
Hi all,
I'm using the form's clean() method to do validation for models in admin.
The validation we need to do is to make sure there are no more than a
certain number of items totally submitted. So I calculate the total number
of items in the clean() method and check whether it is in the given range.
But the exact total number is difficult ot get because I don't know
whether the newly submitted form'data is a modified item that is already
submitted or it's a newly added item. So is there any way in the clean()
method to know whether the form's data is a newly added item or a modified
one?
Thanks to all.
Check the value of self.instance. If it exists, and it has a pk, then
it is a modification rather than an add.
--
DR.
--------------------------------------------------------------------------------
--
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.
--
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.