class Category(models.Model):
name = models.CharField(maxlength=70, unique=True)
slug = models.SlugField(maxlength=50, unique=True,
prepopulate_from=('naam',))
parent = models.ForeignKey('self', blank=True, null=True,
limit_choices_to = {'parent__isnull': True})
def save(self):
try:
cur_id = int(self.id)
except:
cur_id = None
if cur_id and self.parent_id:
if int(self.parent_id) == cur_id:
raise validators.ValidationError("Same parent and child ")
super(Categorie, self).save()
I tried everything but I can't find a better approach than to use the
save method.
Custom validator: no object_id to check upon.
Custom manipulator: doesn't seem to work in admin.
So I cry for help on this one...
> This is my model and I use a custom save to prevent the creation of a
> category with a parent_id which is the same a the current_id (child of
> itself)
When an error occurs an ugly error message apears so I tried to create
a custom validator.
Custom validator didn't work because of "no object_id to check upon".
Creating a Custom manipulator doesn't seem to work in admin.
Can someone show me a solution to get the validation done in admin?
Thanks