0

So I have this class, CreateView, I use it to add a new location to the model location.model. It describes a certain location with coordinates and a small description.

Since I set the I18N settings to True, the decimalField will use comma separated inputs. Since they're coordinates, I would like the use the "." as separator.

forms.DecimalField(max_digits=16, decimal_places=14, localize=False)

Is there such an option with CreateView, I'd like to use the current view instead of rewriting to a form view.

My settings

#settings.py
LANGUAGE_CODE = 'nl'
TIME_ZONE = 'Europe/Amsterdam'
USE_I18N = True
USE_L10N = True

Any other solution would be great, other than I'd like to use the generic class based views.

Alasdair
  • 298,606
  • 55
  • 578
  • 516
Kevin D.
  • 315
  • 2
  • 19

1 Answers1

2

Create a model form that uses your DecimalField

class MyForm(forms.ModelForm):
    my_field = forms.DecimalField(max_digits=16, decimal_places=14, localize=False)

    class Meta:
        model = MyModel
        fields = ['my_field', ...]

Then use that form class in your create view:

class MyCreateView(CreateView):
    form_class = MyForm
    ...
Alasdair
  • 298,606
  • 55
  • 578
  • 516
  • Thanks for the answer, unfortunately it doesn't seem to be working on my end. If i set my decimalfield in forms on "localize=False" it still uses the "," as a separator to be put in the model. Am I missing something here? – Kevin D. Jul 04 '17 at 18:56
  • I can't tell why it isn't working from the information you have given. – Alasdair Jul 04 '17 at 20:31