def clean_parent(self):
        data = self.cleaned_data['parent']
        if data is not None and self.instance in data.path_list():
            raise forms.ValidationError(
                _("This would create a loop in the hierarchy"))

        return data
dataset/ETHPy150Open feincms/feincms/feincms/module/medialibrary/forms.py/MediaCategoryAdminForm.clean_parent/original