Hi all!

I have a modelform and I want to customize validation.

I'm overriding the method clean_<field>().

When I'm saving the form I want to see if a specific user has been already 
assigned to a project. The only way he can ben assigned again is if he's an 
inactive user, so:

models.py
Class User(models.Model):
        name = models.CharField(...)
        active = models.BooleanField()
        ...

Class Project(models.Model):
        user = models.ForeignKey(User)
        ....
******************

forms.py
Class ProjectForm(ModelForm)
        ....
        def clean_name(self):
                user = self.cleaned_data['user']
                if User.objecs.filter(user.id, active=True):
                        raise forms.ValidationError(_("This man has been 
already assign 
to a partner"))
                return user


When I'm creating a new project it works fine (I believe, haven't been tested 
yet), but when editing it throws an error because the user already exists, and 
that's obvious. So, I want to be able to verify if it is a new instance or if 
it is an instance being edited. 

                
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.

Reply via email to