Search code examples
djangomodelverbose

Django - How can I set/change the verbose name of Djangos User-Model attributes?


I'm building a website which contains several languages.

Therefore I need to set verbose names of all attributes in all my model classes (with the internationalizaton-helper). Unfortunately I don't find a way to change the verbose names of the user attributes...

And overwriting every single form isn't really a nice way to do it, right?

Thanks for your help!

Ron


Solution

  • It depends on what you need this for. Generally, verbose_name is only used within the context of the admin. If that's what you need to worry about, then you can create a proxy model and then make your user admin use that:

    from django.contrib.auth.models import User
    from django.utils.translation import ugettext_lazy as _
    
    class CustomUser(User):
        class Meta:
            proxy = True
            app_label = 'auth'
            verbose_name = _('My Custom User')
    

    Then, in admin.py:

     from django.contrib.auth.admin import UserAdmin
     from django.contrib.auth.models import User
    
     from .models import CustomUser
    
     admin.site.unregister(User)
     admin.site.register(CustomUser, UserAdmin)