Django 1.9中的django.db.models.loading.get_model()相当于什么? [英] What is the equivalent of django.db.models.loading.get_model() in Django 1.9?

查看:508
本文介绍了Django 1.9中的django.db.models.loading.get_model()相当于什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 get_model()以避免在我的模型中循环导入,但是我得到名称'get_model'未定义错误。我读到 get_model()在1.8中被折旧,显然在1.9中不存在。什么是等价电话?或者还有另一种方法可以避免在两个 models.py 文件中循环导入?

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?

推荐答案

django.db.models.loading.get_model()已在django 1.9中删除。

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

您应该使用 django.apps

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

Django文档参考

这篇关于Django 1.9中的django.db.models.loading.get_model()相当于什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆