djangodjango-models

Get class name of django model


I have a django model:

class Book(models.Model):
  [..]

and I want to have the model name as string: 'Book'. When I try to get it this way:

Book.__class__.__name__

it returns 'ModelBase'.

Any idea?


Solution

  • Try Book.__name__.

    Django models are derived from the ModelBase, which is the Metaclass for all models.