Django应用程序不会显示在管理员中

时间:2012-02-28 21:47:56

标签: python django

我一直在尝试使用新的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)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

1 个答案:

答案 0 :(得分:3)

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上回答你,但你在我发布答案时正确注销了。如果你要在网上垃圾邮件问题,请等待答案。我几乎没有在这里追你。

相关问题