<p>我想我也许能解决这个问题,因为这不是模型集,而是选择本身的问题。
知道选择被保存为关键整数。你知道吗</p>
<p>现在,我希望在网络上研究一下后,能解决您的问题的解决方案是:</p>
<pre><code>from django.utils.translation import ugettext_lazy as _
def translate_choices(choices):
"""
Returns tuples of localized choices based on the dict choices parameter.
Uses lazy translation for choices names.
"""
return tuple([(k, _(v)) for k, v in choices.items()])
class Issue(models.Model):
PEOPLE = 'PE'
OWNERS = 'OW'
EXPERIENCED_PEOPLE = 'EX'
HELPER_CHOICES = ((PEOPLE, _('People')),
(OWNERS, _('Owners')),
(EXPERIENCED_PEOPLE, _('People with experience')))
who_can_help = models.CharField(_('Who can help?'),
blank=False,
choices=translate_choices(HELPER_CHOICES),
default=PEOPLE,
max_length=2,
null=False)
doggo = models.ForeignKey(Doggo, on_delete=models.CASCADE)
</code></pre>
<ul>
<li>可以对其他选项字段重复使用translate\u choices函数。你知道吗</li>
<li>坏的一面:垃圾箱/制造_消息.py无法自动获取选项值,您必须手动将它们添加到.po中。你知道吗</li>
</ul>
<p>这里有一个简单的循环来翻译每个选项,您可以通过设置<code>choices=translate_choices(CHOICES)</code>与<code>translate_choices</code>对话。你知道吗</p>
<p>Hoop dat dit je wat verder helpt;)</p>