verbose_name for ManyToManyField not displayed

2019-07-28 23:25发布

the verbose_name I set for a ManyToManyField is not displayed in my admin. Is that because I override the form? Anybody can help?

Thanks!

models.py

class PC(models.Model):
    #...
    mag_blacklist = models.ManyToManyField(Magasin, verbose_name="test")

admin.py

class PCForm(forms.ModelForm):
    mag_blacklist = forms.ModelMultipleChoiceField(queryset=Magasin.objects.all(), widget=forms.CheckboxSelectMultiple())

标签: django admin
1条回答
叛逆
2楼-- · 2019-07-29 00:09

Yep, I am pretty much sure thats why! just change the label in your form field then:

mag_blacklist = forms.ModelMultipleChoiceField(queryset=Magasin.objects.all(), widget=forms.CheckboxSelectMultiple(), label="test")

Or you can get the actual verbose like this:

mag_blacklist = forms.ModelMultipleChoiceField(queryset=Magasin.objects.all(), widget=forms.CheckboxSelectMultiple(), label=Magasin._meta.get_field_by_name('mag_blacklist')[0].verbose_name)

try it out! lemme know if works

查看更多
登录 后发表回答