Luke Plant wrote:
> On Wednesday 31 May 2006 07:36, favo wrote:
> > somebody know how to use instance method in the validator_list of a
> > field in model? I can't get the "self".
> >
> > class Category(models.Model):
> > """ Inhert Category """
> >
> > title_en = models.CharField(maxlength=256, null=True)
> >
> > parent = models.ForeignKey('self',
> > related_name="direct_children", null=True, blank=True,
> > validator_list=[self.isValidParent]) # we want the instance method
> > here
> >
> > def isValidParent(self, field_data, all_data):
> > if field_data in self.children_ids()
> > raise validators.ValidationError("u can't set your
> > children as your parent, cause loop")
>
> You can't do this -- validator functions take just field_data and
> all_data. In fact, an instance might not even exist when the validator
> is called -- when creating a new instance, f> On Wednesday 31 May 2006 07:36,
> favo wrote:
> > somebody know how to use instance method in the validator_list of a
> > field in model? I can't get the "self".
> >
> > class Category(models.Model):
> > """ Inhert Category """
> >
> > title_en = models.CharField(maxlength=256, null=True)
> >
> > parent = models.ForeignKey('self',
> > related_name="direct_children", null=True, blank=True,
> > validator_list=[self.isValidParent]) # we want the instance method
> > here
> >
> > def isValidParent(self, field_data, all_data):
> > if field_data in self.children_ids()
> > raise validators.ValidationError("u can't set your
> > children as your parent, cause loop")
>
> You can't do this -- validator functions take just field_data and
> all_data. In fact, an instance might not even exist when the validator
> is called -- when creating a new inor example.
>
> However, you can override the 'validate' method on a model, and you
> might be able to use that to do what you want (you will probably want a
> validate method that looks like this:
>
> class Category(models.Model):
> ## fields etc here
> def validate(self):
> error_dict = super(Category, self).validate()
> # Do your validation here, adding to 'error_dict'
> # and then:
> return error_dict
How could these happen?
I see some code in change_stage, it will only call
errors = manipulator.get_validation_errors(new_data)
No one run the validate method of model?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---