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

前端 未结 1 1789
一整个雨季
一整个雨季 2020-12-10 00:54

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()

相关标签:
1条回答
  • 2020-12-10 01:04

    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

    0 讨论(0)
提交回复
热议问题