Import model from another app Django

前端 未结 2 1240
滥情空心
滥情空心 2021-02-06 11:27

I have a problem importing a model from another app. I am using Django 2.0.

My project structure looks like this:

--api
  --api
    --settin         


        
2条回答
  •  孤独总比滥情好
    2021-02-06 12:06

    The solution I found that works for me using Python 3.x

    ...
    from django.apps import apps
    ...

    and then whereever in your code you need to import a model you can do the following.
    ...
    model = apps.get_model('app_name', 'ModelName')
    ...

提交回复
热议问题