code: def get_form(self, request, obj=None, **kwargs):
          
          parent_id = request.REQUEST.get('parent_id', None)
          if parent_id:
              return FolderForm
          else:
              folder_form = super(FolderAdmin, self).get_form(
                  request, obj=None, **kwargs)
  
              def folder_form_clean(form_obj):
                  cleaned_data = form_obj.cleaned_data
                  folders_with_same_name = Folder.objects.filter(
                      parent=form_obj.instance.parent,
                      name=cleaned_data['name'])
                  if form_obj.instance.pk:
                      folders_with_same_name = folders_with_same_name.exclude(
                          pk=form_obj.instance.pk)
                  if folders_with_same_name.exists():
                      raise ValidationError(
                          'Folder with this name already exists.')
                  return cleaned_data
  
              # attach clean to the default form rather than defining a new form
              # class
              folder_form.clean = folder_form_clean
              return folder_form
docs: Returns a Form class for use in the admin add view. This is used by
          add_view and change_view.