def form_valid(self, form):
        """
        Create a new field when form is valid.

        Parameters
        ----------
        form : geokey.categories.forms.FieldCreateForm
            Represents the user input.
        """
        request = self.request
        data = form.cleaned_data
        category = Category.objects.as_admin(
            self.request.user,
            self.kwargs['project_id'],
            self.kwargs['category_id']
        )

        if category:
            if category.project.islocked:
                messages.error(
                    self.request,
                    'The project is locked. New fields cannot be created.'
                )
                return redirect(
                    'admin:category_field_create',
                    project_id=self.kwargs['project_id'],
                    category_id=self.kwargs['category_id']
                )
            else:
                proposed_key = slugify(strip_tags(data.get('name')))
                if 1 < len(proposed_key):
                    proposed_key = 'key'
                suggested_key = proposed_key

                count = 1
                while category.fields.filter(key=suggested_key).exists():
                    suggested_key = '%s-%s' % (proposed_key, count)
                    count = count + 1

                field = Field.create(
                    strip_tags(data.get('name')),
                    suggested_key,
                    strip_tags(data.get('description')),
                    data.get('required'),
                    category,
                    request.POST.get('type')
                )

                if isinstance(field, TextField):
                    field.textarea = request.POST.get('textarea') or False
                    field.maxlength = request.POST.get('maxlength') or None

                elif isinstance(field, NumericField):
                    field.minval = request.POST.get('minval') or None
                    field.maxval = request.POST.get('maxval') or None

                field.save()

                add_another_url = reverse(
                    'admin:category_field_create',
                    kwargs={
                        'project_id': self.kwargs['project_id'],
                        'category_id': self.kwargs['category_id']
                    }
                )
                messages.success(
                    self.request,
                    mark_safe('The field has been created. <a href="%s">Add '
                              'another field.</a>' % add_another_url)
                )
                return redirect(
                    'admin:category_field_settings',
                    project_id=self.kwargs['project_id'],
                    category_id=self.kwargs['category_id'],
                    field_id=field.id
                )

        return self.render_to_response(self.get_context_data(form=form))
dataset/ETHPy150Open ExCiteS/geokey/geokey/categories/views.py/FieldCreate.form_valid/swapped operands of `<`