[英]Django app won't show up in admin
我一直在嘗試使新的Django應用程序正常工作,在此我使用ForeignKey調用另一個模型。 一切似乎在我的本地計算機上運行良好,並且按預期方式顯示。
但是,當我在生產服務器上嘗試此操作時,它只是無法正常工作。 我已經搞混了太久了,我覺得是時候使用大槍了,在這里問問題;)
這種情況:
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)省份型號
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 admin功能編輯應用程序時,它也不會顯示在admin中。
我很確定這兩個問題是相關的,我希望有人遇到類似的事情,或者只是知道我在這里應該做什么。 我開始感覺到某個地方存在內部沖突,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上回答了您,但您在我發布答案時就注銷了。 如果您要在整個網絡上發送垃圾郵件,請等待答案。 我差點沒在這里追你
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.