【发布时间】:2017-09-27 17:53:18
【问题描述】:
Python:3.6.2 Django:1.11.4
我们正在尝试跨应用使用外键。客户和代理都使用地址。我们也在使用内联框架集。如果我将所有这些都放在一个应用程序中,它可以正常工作,包括内联框架集。如果我拆分为多个应用程序,则会出现此错误。请看下面的图片。
File "C:/Users/palak/Desktop/mergemodels\apps\sharedmodels\models.py", line 15, in <module>
class Address(models.Model):
File "C:/Users/palak/Desktop/mergemodels\apps\sharedmodels\models.py", line 16, in Address
agent = models.Foreignkey('apps.agent.Agent')
TypeError: object() takes no parameters
<BLOCKQUOTE>
应用程序(文件夹)
代理(应用程序)
模型.py
客户(应用程序)
模型.py
共享模型(应用程序)
模型.py
请注意以上文件夹结构的应用程序。
sharedmodels/models.py
from django.db import models
#from apps.agent.models import Agent
class ContactInfo(models.Model):
mobile_no = models.CharField(max_length=8)
phone_no = models.CharField(max_length=10)
class Location(models.Model):
location_name = models.CharField(max_length=50)
city = models.CharField(max_length=20, blank=True, null=True)
state = models.CharField(max_length=20, blank=True, null=True)
class Address(models.Model):
#agent = models.Foreignkey(Agent)
address1 = models.CharField(max_length=100)
address2 = models.CharField(max_length=100)
代理/models.py
from django.db import models
from apps.sharedmodels.models import Location, Address, ContactInfo
class Agent(models.Model):
first_name = models.CharField(max_length=20)
location = models.ManyToManyField(Location)
address = models.Foreignkey(Address)
contactinfo = models.OneToOneField(ContactInfo)
客户/models.py
from django.db import models
#from apps.agent.models import Agent, Address
from apps.sharedmodels.models import ContactInfo, Address
class Customer(models.Model):
first_name = models.CharField(max_length=10)
#address = models.OneToOneField(Address)
contactinfo = models.OneToOneField(ContactInfo)
address = models.Foreignkey(Address)
Settings.py - installapps 部分
# Application definition
INSTALLED_APPS = [
'apps.customer',
'apps.agent',
'apps.sharedmodels',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
【问题讨论】:
-
非常感谢任何即时帮助
-
你能不能输入你的错误而不是你的错误的链接,文件夹结构也一样?
标签: python django django-models