3👍
✅
You can query the _meta
(Options
) API of the related model for the db_table
attribute:
related_field.related_model._meta.db_table
For example:
for field in instance._meta.concrete_fields:
if isinstance(field, models.ForeignKey):
print(field.related_model._meta.db_table)
Source:stackexchange.com