How to stop auto-capitalization of verbose_name in django

后端 未结 5 827
野趣味
野趣味 2021-01-03 06:45

How to prevent Django from auto-capitalizing of the verbose_name in models? E.g:

class TestModel(models.Model):
    enb_id = models.IntegerField(null=True, v         


        
5条回答
  •  温柔的废话
    2021-01-03 07:04

    I believe that the "most correct" answer in modern Django (v1.11+) is to do the following:

    class TestModel(models.Model):
        field_name = models.CharField(verbose_name=_('field name'), blank=True)
    
    
    class TestModelForm(forms.ModelForm):
        class Meta:
            model = TestModel
            fields = '__all__'
            labels = {
                'field_name': _('field name')
            }
    

    This doesn't require you to define a custom model field just to change the form, use custom CSS, or hack around browser behavior. It's laser-targeted to only change the string that gets sent to the form renderer for that one field, with absolutely no other potential knock-on effects.

提交回复
热议问题