python – 来自models.py文件的Django Splitting模型
发布时间:2020-12-20 13:38:48 所属栏目:Python 来源:网络整理
导读:我试图将所有模型与models.py文件分开.我在做什么在这个 link中提到过.但问题是我的一个模型是django.contrib.auth.user我在models.py中拧了一个函数如下生成令牌. def create_user_profile(sender,instance,created,**kwargs): if created: UserProfile.obj
我试图将所有模型与models.py文件分开.我在做什么在这个
link中提到过.但问题是我的一个模型是django.contrib.auth.user我在models.py中拧了一个函数如下生成令牌.
def create_user_profile(sender,instance,created,**kwargs): if created: UserProfile.objects.create(user=instance) post_save.connect(create_user_profile,sender=User) 那么如何在_init_.py文件中导入该东西,因为我们将模型导入为 from myapp.models.foo import Foo 解决方法
你应该只有models.py或models / __ init__.py,看起来你们两个都有.其中一个模块可能会影响另一个模块,所以不要两者兼顾(即摆脱models.py)
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |