[Django]-Django: get table name of a model in the model manager?

73👍

✅

Model manager has the field model:

Model.objects.model._meta.db_table

14👍

For a given instance, you can use instance._meta.db_table but that also works for the model class too, so if you can step up from the manager to its model, that’ll work too

11👍

Let’s say you have a model named Service

You can use

Service._meta.db_table # this will work too

This as well

Service.objects.model._meta.db_table # this will work too

This as well
Let’s say you had an instance of the service Model like this

service = Service.objects.get(pk=1)
# get table name like this
table_name = service._meta.db_table # this will work too

Leave a comment