How to stop auto-capitalization of verbose_name in django
问题内容:
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, verbose_name="eNB ID", blank=True)
I want to handle the capitalization myself and display “eNB ID” instead of
“ENB ID” anywhere on the site.
问题答案:
It seems like the simple workaround for this is adding a whitespace at the
beginning of verbose_name
. Function that performs the capitalization
(capfirst
) changes only the first letter. If it is a whitespace nothing will
be changed. Because web browsers ignore consecutive whitespaces everything
will be displayed correctly.
class TestModel(models.Model):
enb_id = models.IntegerField(null=True, verbose_name=" eNB ID", blank=True)
class Meta:
verbose_name = " test model"