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 that Django capitalizes the first letter when setting the form field for that model field:
...
defaults = {
'required': not self.blank,
'label': capfirst(self.verbose_name),
'help_text': self.help_text
}
You could create your own custom model field that overwrites the capfirst
(by passing the label as kwarg):
from django.db import models
class UpcappedModelField(models.Field):
def formfield(self, form_class=forms.CharField, **kwargs):
return super(UpcappedModelField, self).formfield(form_class=forms.CharField,
label=self.verbose_name, **kwargs)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With