[Answer]-Changing label in auth.User model field

1👍

A Django model’s fields are moved to Model._meta at class initialization, since Django 1.8, you can access them using the _meta API.

Also, label is an attribute of form fields, the equivalent for model fields is verbose_name.

This should work an Django 1.8

class CustomUser(AbstractUser):
    mobile = models.CharField(max_length=16)
    address = models.CharField(max_length=100)

    def __init__(self, *args, **kwargs):
        super(CustomUser,self).__init__(*args, **kwargs)
        self._meta.get_field('username').verbose_name = 'Some text'

Before Django 1.8 you can use self._meta.get_field_by_name('username')[0] instead of self._meta.get_field('username').

👤aumo

Leave a comment