我一直在試圖讓一個新的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
如果您發佈的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