我尝试翻译Django管理网站,但ManyToMany
TabularInline
出现问题。我的models.py
是:
class Doctor(models.Model):
(...)
specializations = models.ManyToManyField(Specialization, blank=True, verbose_name='Specjalizacje')
class Meta:
verbose_name = 'Lekarz'
verbose_name_plural = 'Lekarze'
class Specialization(models.Model):
name = models.CharField(max_length=191, verbose_name='Nazwa')
class Meta:
verbose_name = 'Specjalizacja'
verbose_name_plural = 'Specjalizacje'
我的admin.py
看起来像:
class SpecializationInline(admin.TabularInline):
model = Doctor.specializations.through
verbose_name = 'Specjalizacja'
verbose_name_plural = 'Specjalizacja'
@admin.register(Specialization)
class SpecializationAdmin(admin.ModelAdmin):
list_display = ['name',]
@admin.register(Doctor)
class DoctorAdmin(admin.ModelAdmin):
inlines = [SpecializationInline,]
# this field is added as inline
exclude = ['specializations',]
除了“专业化”和“专业化”之外,所有内容都被翻译。柱。我该如何更改其名称?
答案 0 :(得分:2)
Oke,这不是一个完整的解决方案。但我希望这会帮助你。
在Symfony 2.8.32
,TabularInline
。
构建表格“标题”部分的部分
admin/edit_inline/tabular.html
这告诉我你可以在字段中添加标签。所以通过创建自定义表单
<thead><tr>
...
{% for field in inline_admin_formset.fields %}
{% if not field.widget.is_hidden %}
<th{% if field.required %} class="required"{% endif %}>
{{ field.label|capfirst }}
...
</th>
{% endif %}
{% endfor %}
...
</tr></thead>
并在class SpecializationForm(ModelForm):
specializations = forms.ModelChoiceField(queryset=Specialization.objects.all(), label='Specjalizacja')
class Meta:
model = Specialization
fields = ('specializations', )
SpecializationInline
这应该允许您更改文本。