def clean(self):
        super(MenuItemFormMixin, self).clean()
        content_type = self.cleaned_data['content_type']
        object_id = self.cleaned_data['object_id']
        if (content_type and not object_id) or (not content_type and object_id):
            raise forms.ValidationError(
                "Both 'Content type' and 'Object id' must be specified to use generic relationship"
            )
        if content_type and object_id:
            try:
                obj = content_type.get_object_for_this_type(pk=object_id)
            except ObjectDoesNotExist as e:
                raise forms.ValidationError(str(e))
            try:
                obj.get_absolute_url()
            except AttributeError as e:
                raise forms.ValidationError(str(e))

        if 'is_enabled' in self.cleaned_data and \
           self.cleaned_data['is_enabled'] and \
           'link' in self.cleaned_data and \
           self.cleaned_data['link'].startswith('^'):
            raise forms.ValidationError('Menu items with regular expression '
                                        'URLs must be disabled.')
        return self.cleaned_data
dataset/ETHPy150Open caktus/django-treenav/treenav/forms.py/MenuItemFormMixin.clean/original