Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django - How to access the verbose_name of a Model in its Admin Module?

How to access the verbose_name of a Model in its Admin Module? We can access the same if we have an instance of that model like below.

instance._meta.verbose_name.title() 
like image 965
Sivasubramaniam Arunachalam Avatar asked Nov 01 '10 15:11

Sivasubramaniam Arunachalam


People also ask

How do you get the verbose model name?

verbose_name. title() returns verbose name with First Character Uppercase while Model. _meta. verbose_name_raw property returns the verbose name you wrote in the model class.

What is the use of Verbose_name in Django model?

verbose_name is 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. This attribute in general changes the field name in admin interface.

How do I change app label in Django admin?

Rename the folder which is in your project root. Change any references to your app in their dependencies, i.e. the app's views, the urls.py and settings.py files. Edit the database table django_content_type with the following command: UPDATE django_content_type SET app_label='' WHERE app_label=''

What is admin panel in Django?

Django provides a built-in admin module which can be used to perform CRUD operations on the models. It reads metadata from the model to provide a quick interface where the user can manage the content of the application. This is a built-in module and designed to perform admin related tasks to the user.


2 Answers

Model._meta.verbose_name.title()

and

Model._meta.verbose_name_plural.title()

return singular and plural Model's verbose names accordingly. There's also Model._meta.verbose_name_raw property, it seems to return unicode string for me, while verbose_name.title() returns a normal string, but I'm not sure what's the real difference between this and verbose_name.title().

like image 142
allait Avatar answered Sep 21 '22 12:09

allait


Model._meta.verbose_name.title() returns verbose name with First Character Uppercase while Model._meta.verbose_name_raw property returns the verbose name you wrote in the model class.

like image 40
Pegasus Avatar answered Sep 20 '22 12:09

Pegasus