derek-schaefer / django-json-field

Generic JSON model and form fields.
BSD 3-Clause "New" or "Revised" License
122 stars 86 forks source link

`JSONFormField.clean` should return a python object and not it's string representation. #22

Closed charettes closed 11 years ago

charettes commented 11 years ago

Is there a reason why you don't return the json.loads?

e.g. forms.DateField.clean returns a date and forms.BooleanField.clean returns a bool.

derek-schaefer commented 11 years ago

In my case, I only needed to validate the JSON and return it. However, I can see how returning a Python object would be useful. Perhaps a flag parameter on clean would be best.

charettes commented 11 years ago

This is definitely a misbehavior, does IntegerField.clean returns a an integer in it's string form '123' or as integer int.

Stating Django's form documentation:

In general, any cleaning method can raise ValidationError if there is a problem with the data
it is processing, passing the relevant error message to the ValidationError constructor. If no
ValidationError is raised, the method should return the cleaned (normalized) data as
a Python object.
derek-schaefer commented 11 years ago

Indeed. This will be taken care of soonTM. Pull requests are always welcome.

derek-schaefer commented 11 years ago

Change applied.