Given a model's instance object, how can I get the database table's name?
I don't want to specify names explicitly in the Meta class.
You can get table name simply call getTable() of model object, so how to call this method as bellow example. $item = new Item; $table = $item->getTable(); print_r($table);
A model's database table name is constructed by joining the model's “app label” – the name you used in manage.py startapp – to the model's class name, with an underscore between them.
The instance model is made up of Instances and links that are based on the class model. An Instance is an instance of a Class, Data Type, Interface or Signal that that shows features (Attributes and Roles) of that item through Slots. Each Slot corresponds to a single feature, and a Slot may include a value.
Found the answer myself: the _meta attribute of an instance has the information:
model_instance._meta.db_table
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With