Django: combine lazy translation with mark safe in model choices

前端 未结 1 1544
-上瘾入骨i
-上瘾入骨i 2021-01-04 22:54

Yeah, so, I want to store translated choices for my model, but Django disagrees with me on this one. Version of Django is 1.3 and the model and choices look something like t

相关标签:
1条回答
  • 2021-01-04 23:03

    Add:

    from django.utils import six  # Python 3 compatibility
    from django.utils.functional import lazy
    from django.utils.safestring import mark_safe
    from django.utils.translation import ugettext_lazy as _
    
    mark_safe_lazy = lazy(mark_safe, six.text_type)
    

    And then:

    mark_safe_lazy(string_concat('€ 0,05 ', _('per minute')))
    

    This was added to Django 1.4 docs.

    0 讨论(0)
提交回复
热议问题