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 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)

Django always capitalizes a model's verbose name in admin index , How to stop auto-capitalization of verbose_name in django in the admin index page, Django always capitalizes the first letter of the model's  In the absence of the other patch, I don't think it makes sense to remove auto-capitalization of user-defined verbose names as the existing convention is to define those as lower-cased strings and rely on Django to do capitalization as necessary. Of course, sometimes this isn't desired, but changing it will be backwards-incompatible.


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"

#26497 (No Capitalization of user-defined verbose_names of model , "Disable capitalization of verbose_name of model fields in forms" ? I did a quick review of the patch and opened PyCharm with a fresh Django 1.9.5 installation. makes sense to remove auto-capitalization of user-defined verbose names as  spaasis commented on Aug 29, 2017. Hi, I have some columns in my table that use specified units, for example Amount (mg). I have this defined in the model's verbose_name, and it shows as intended in for example Django Admin.


Adding verbose_name in Meta class works for me.

from django.db import models

class Artist(models.Model):
    name = models.CharField("Artist", max_length=255, unique=True)

    class Meta:
        verbose_name = "Artist"
        verbose_name_plural = "aRTiStS"

result:

#18129 (Capitalization of verbose_name bad design decision. Why , Capitalization of verbose_name bad design decision. Why waste But to capitalize verbose_names is an waste of computer power and makes django slower. is explicitely set it should at least be possible to disable automatic capitalisation. verbose_name: A human-readable name for the field. If the verbose name isn’t given, Django will automatically create it using the field’s attribute name, converting underscores to spaces. validators: A list of validators to run for this field. See the validators documentation for more information. Unique


if one needs all fields names to start with first character lowercase (e.g. in create forms), this can be set for label in css:

label:first-letter {
    text-transform: lowercase;
}

Tables overrides model's verbose_name with auto-capitalization , I have this defined in the model's verbose_name, and it shows as intended in for example Django Admin Django will automatically capitalize the first letter where it needs to. Disable titlized/capitalized colum headers #491. Test._meta.get_field("name").verbose_name.title() If you want to use this in template then it will be best to register template tag for this. Create a templatetags folder inside your app containing two files ( __init__.py and verbose_names.py ).Put following code in verbose_names.py :


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.

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  I would like to rename all the Groups field in Django admin as Roles field. But there are still some parts that didn't changed. I have successfully renamed Groups into Roles using this code (model


Beginning Django: Web Application Development and Deployment with , Web Application Development and Deployment with Python Daniel Rubio of a Django form field using a capitalized version of the model field name. You can configure more verbose form field headers with the verbose_name option (e.g., models. Be aware that under the following circumstances Django automatically​  How to stop auto-capitalization of verbose_name in django. Related. 11. Free-form input for ForeignKey Field on a Django ModelForm. 22. Django modelForm and html


Django Best Practices: Models, A list of tips for designing better models in Python/Django. Models should always be Capitalized (eg. A common example is for a blog app that needs to automatically set the author of a blog post to the current logged-in class Meta: verbose_name = 'university' verbose_name_plural = 'universities'. GenericIPAddressField is a Django ORM for mapping from your Python code to an database column that needs to store a valid IP address.. The Django project has great documentation for GenericIPAddressField as well as all of the other column fields.


Models, CASCADE, verbose_name="the related poll", ) sites = models. Django will automatically capitalize the first letter where it needs to. The clear() method can be used to remove all many-to-many relationships for an instance: >  django.db.models AutoField Example Code AutoField is a Django ORM mapping from your Python code to an integer-type column in your relational database . The Django project has great documentation for AutoField as well as all of the other column fields.