Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent of django.db.models.loading.get_model() in Django 1.9?

Tags:

django

I want to use get_model() to avoid cyclic imports in my models, but I get name 'get_model' is not defined error. I read that get_model() was depreciated in 1.8 and apparently is not present in 1.9. What is the equivalent call? Or is there another way to avoid cyclic imports in two models.py files?

like image 348
Zygro Avatar asked Mar 26 '16 11:03

Zygro


Video Answer


1 Answers

django.db.models.loading.get_model() has been removed in django 1.9.

You are supposed to use django.apps instead.

>>> from django.apps import apps >>> apps.get_model('shop', 'Product') <class 'shop.models.Product'> >>>  

Django docs reference

like image 176
v1k45 Avatar answered Sep 30 '22 17:09

v1k45