我遇到babel
documentation,我想在具有currencies = models.ChoiceField
的模型中使用它。如何使用babel内置货币列出上述字段名称?
答案 0 :(得分:1)
如果您想使用Babel,可以尝试这样的事情:
from babel.numbers import list_currencies
CURRENCY_CHOICES = [(currency, currency) for currency in list_currencies()]
# `choices` has to be an iterable (e.g., a list or tuple) consisting
# itself of iterables of exactly two items from which first of values is
# stored in database and the second is for representation.
class ModelName(models.Model):
currency = models.CharField(
max_length=3, null=True, blank=True, choices=CURRENCY_CHOICES
)
currency_with_default = models.CharField(
max_length=3, default='USD', choices=CURRENCY_CHOICES
)