[英]Accessing a single model between multiple apps - Django
I have a Django project with two app that are users and groups. 我有一个包含两个应用程序的Django项目,分别是用户和组。 I have a model named Friend in the users app. 我在用户应用程序中有一个名为Friend的模型。 I want to access the model in the groups app. 我想在群组应用中访问模型。 How can I import the Friend model from the users app within the groups app. 如何从网上论坛应用中的用户应用导入朋友模型。 I want to access the other models to make queries and querysets in the groups app from the models in the groups app. 我想访问其他模型,以从组应用程序中的模型在组应用程序中进行查询和查询集。
Here are the import statements I have right now... 这是我现在拥有的导入语句...
Imports for the views in the users app: 导入用户应用程序中的视图:
from .forms import *
from .method import *
from .models import *
Imports for the veiws in the groups app: 在分组应用中导入veiws:
from .forms import *
from .models import *
How can i import the users models in the groups app. 如何在网上论坛应用中导入用户模型。 I also want to import the groups models in the users models. 我也想在用户模型中导入组模型。
Here is the current directory.... 这是当前目录。
from [app].models import [model] 从[app] .models导入[model]
from user.models import Class
Or 要么
from groups.models import Class
Be sure you have created __init__.py files on every app directory 确保已在每个应用程序目录上创建__init__.py文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.