#22654: DecimalField and DECIMAL_SEPARATOR (in admin) --------------------------+------------------------------------ Reporter: matija@… | Owner: (none) Type: Bug | Status: new Component: Forms | Version: 1.6 Severity: Normal | Resolution: Keywords: | Triage Stage: Accepted Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 --------------------------+------------------------------------
Comment (by tonnzor): I have the same issue. It is very easy to reproduce: {{{#!python # in settings.py LANGUAGES = (('de', 'German'),) LANGUAGE_CODE = 'de' # in models.py CHOICES = ( (Decimal('0.25'), '0.25d'), (Decimal('0.50'), '0.5d'), (Decimal('0.75'), '0.75d'), (Decimal('1.00'), '1d'), ) class Number(models.Model): num = models.DecimalField(max_digits=3, decimal_places=2, choices=CHOICES) # in admin.py @admin.register(Number) class NumberAdmin(admin.ModelAdmin): pass }}} If you go to admin and try to save it would give you a validation error. Reason is that it generates following HTML -- see comma in value: {{{ <select name="num" id="id_num"> <option value="0,25">0.25d</option> <option value="0,50">0.5d</option> <option value="0,75">0.75d</option> <option value="1,00" selected="">1d</option> </select> }}} But when you provide choices -- it would be TypedChoiceField. Somehow it cannot handle comma in value and convert it correctly to decimal. Interesting here if you drop choices. Then DecimalField would be used and everything would work -- you would use comma in the field. BUT if you check HTML, it would use dots internally: {{{ <input name="num" value="0.25" step="0.01" required="" id="id_work_days" type="number"> }}} Also, POST request would send dot-separated value, not comma (though comma is shown in UI). It seems if we force TypedChoiceField generate dot-separated HTML for Decimals despite of localization and i18n -- it would fix the issue. -- Ticket URL: <https://code.djangoproject.com/ticket/22654#comment:12> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/077.51120bd41b4addca65db1125fe1785d6%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.