Django应用程序不会显示在管理员
我一直在试图让一个新的Django应用程序工作,在那里我使用ForeignKey调用另一个模型。在我的本地机器上似乎都很顺利,它按预期显示。Django应用程序不会显示在管理员
但是,当我在我的生产服务器上尝试此操作时,它只是不起作用。我一直在瞎搞这个太久了,我觉得现在是时候大枪在这里问的问题;)
情况是这样的:
1)customerModel
from django.db import models
from mysite.product.models import Product
from mysite.province.models import provinceModel
from mysite.district.models import districtModel
class customerModel(models.Model):
productId = models.ForeignKey(Product)
name = models.CharField(max_length=30)
province = models.ForeignKey(provinceModel)
district = models.ForeignKey(districtModel)
def __str__(self):
return self.name
2)provinceModel
from django.db import models
class provinceModel(models.Model):
name = models.CharField(max_length=30)
def __str__(self):
return self.name
至于说,这一切工作正常当地。在生产,我想同样的,这让我这个错误:
Error: One or more models did not validate:
customer.customerModel: 'province' has a relation with model <class 'mysite.province.models.provinceModel'>,
which has either not been installed or is abstract.
我猜它是抽象的。既然它肯定安装(settings.py中)。
为了使事情正确,我决定玩弄。我注意到,即使删除了所有代码,并试图使用django管理功能编辑应用程序,它也不会显示在管理员中。
我很确定这两个问题是相关的,我希望有人遇到过类似的东西,或者只是知道我应该在这里做什么。我开始感觉到某处存在内部冲突,Django没有告诉我。由于可以将一些模型添加到ForeignKeys中,例如区域模型,但是新模型不起作用。我也尝试添加另一个新的。
是的,我没有看过其他相关的帖子,关于应用程序没有显示。它们在INSTALLED_APPS下的settings.py中注册。任何帮助深表感谢!
3)的settings.py
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
'mysite.product',
'mysite.intervention',
'mysite.customer',
'mysite.province',
'mysite.part',
'mysite.district',
)
4)目录结构
mysite
-> customer
-> customerModel
-> district
-> districtModel
-> intervention
-> districtModel
-> part
-> partModel
-> product
-> productModel
-> province
-> provinceModel
from django.db import models
# Notice you don't need these imports with string notation
class customerModel(models.Model):
productId = models.ForeignKey('product.Product')
name = models.CharField(max_length=30)
province = models.ForeignKey('province.provinceModel')
district = models.ForeignKey('district.districtModel')
def __unicode__(self): # use __unicode__ !!!
return self.name
尝试。我在IRC上回答了你,但你在我发布答案时正确登出了。如果你要通过网络发送垃圾邮件,请等待答案。我几乎没有在这里追你。
好赶上(__unicode__):P – Paulo 2012-02-28 22:06:21
嗨,Joshua,Thx在这里追我;)我得到了unicode部分,它解决了我一直遇到的一些问题...... thx! 虽然我仍然得到相同的错误。 – 2012-02-28 22:21:52
如果您发布的provinceModel定义是正确的,那么该模型不是抽象的,因为只有在您的Meta类中指定模型时,模型才是抽象的。你能发布你的INSTALLED_APPS设置吗? – Paulo 2012-02-28 22:02:26
粘贴settings.py的INSTALLED_APPS部分以及你的app目录结构。同时指出这些模型究竟在哪里。相同models.py或不同的应用程序。 – Sid 2012-02-28 22:04:17
尝试将所有模型放在同一个文件中。 – santiagobasulto 2012-02-28 22:15:45