How to get which model an object is


I’m trying to get a template to find out which model an object is, then add the name of the model type ti the page.

My model is:

class MyModel(models.Model):

Then my template is:

<h1> The model is: {{ my_object.class }} </h1>

Hopefully I’d get

The model is: MyModel

Would this work?

Many thanks.

Hi @sad_man,

I think what you’re looking for is {{ my_object.__class__.__name__ }}. However, if you’re looking for the model’s verbose name, you could use {{ my_object._meta.verbose_name }}.

1 Like

Thank you again @CodenameTim! I’ll try this on my next work session. Thanks so much for your help. I find the documentation quite dense.