Categories
Python Answers

How to get model from string with Python Django?

Spread the love

To get model from string with Python Django, we can use the get_model function.

For instance, we write

from django.apps import apps

model = apps.get_model('app_name', 'model_name')

to call apps.get_model with the app name and model name as arguments to get the model.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *