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>应用程序(文件夹)
移动代理(app)
models.py 移动客户(app)
models.py *共享机型(App)
models.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)agent/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)customer/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 -安装应用程序部分
# 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',
]发布于 2017-09-28 01:59:32
将外键设置为字符串foreignkey
agent = models.Foreignkey('agent.Agent')
# ^^^^^^^sharedmodels/models.py
from django.db import models
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.Agent', related_name='addresses')
address1 = models.CharField(max_length=100)
address2 = models.CharField(max_length=100)agent/models.py
from django.db import models
class Agent(models.Model):
first_name = models.CharField(max_length=20)
location = models.ManyToManyField('sharedmodels.Location')
address = models.ForeignKey('sharedmodels.Address', related_name='agents')
contactinfo = models.OneToOneField('sharedmodels.ContactInfo')
from django.db import modelscustomer/models.py
class Customer(models.Model):
first_name = models.CharField(max_length=10)
contactinfo = models.OneToOneField('sharedmodels.ContactInfo')
address = models.ForeignKey('sharedmodels.Address')https://stackoverflow.com/questions/46454265
复制相似问题