[Answer]-Loop and Print Verbose_Name of all tables in Django's Model.py

1👍

After much research/combinations was able to find out this is generic behavior of django.
For models not having verbose_name parameter, the table/model name is returned as string.

To achieve my objective, I added verbose_name = 'DNS' for the models for which I didn’t want to display the verbose_name. And in my code i did something like:

if mdl._meta.verbose_name == 'DNS':
    # Do Nothing
else:
    # My Logic.

0👍

You can check what type the verbose name is. If it’s unicode then you can print the name

mdls = models.get_models(include_auto_created=False)
for mdl in mdls:
    if isinstance(mdl._meta.verbose_name, unicode):
        print mdl._meta.verbose_name

Leave a comment