Найти - Пользователи
Полная версия: decial separator
Начало » Django » decial separator
1
max38934
Доброго времени суток. Подскажите пожалуйста как мне изменить сепаратор в поле decial, допустим на ту же запятую?
Проделал следующие шаги:
- в сктингсы добавил:
USE_L10N = True
LANGUAGE_CODE = 'de'
USE_I18N = True
DECIMAL_SEPARATOR = ','
- в модели импортирую:
from django.conf.global_settings import DECIMAL_SEPARATOR
и само поле:
balance = models.DecimalField(max_digits = 6, decimal_places = 2)
пробовал добавлять еще один переметр (3-й) localize=True
в результате чего вылетала следующая ошибка:
File "/home/max/python/herbal/env_herbal/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 752, in __init__
Field.__init__(self, verbose_name, name, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'localize'
max38934
Решение:
class CommaDecimalField(fields.DecimalField):
def to_python(self,value):
return super(CommaDecimalField,self).to_python(value.replace(',','.'))

class FastPayout(forms.Form):
payout_sum = CommaDecimalField(label='Sum', decimal_places=2, max_digits=10)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB