简体   繁体   English

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

[英]Django app won't show up in admin

I've been trying to get a new Django app to work, where I call another Model using a ForeignKey. 我一直在尝试使新的Django应用程序正常工作,在此我使用ForeignKey调用另一个模型。 All seems to be going well on my local machine and it shows up as expected. 一切似乎在我的本地计算机上运行良好,并且按预期方式显示。

However, when I try this on my production server, it's just not working. 但是,当我在生产服务器上尝试此操作时,它只是无法正常工作。 I've been messing around with this for too long now, and I feel it's time for the big guns and ask the question here ;) 我已经搞混了太久了,我觉得是时候使用大枪了,在这里问问题;)

This is the situation: 这种情况:

1) customerModel 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 2)省份型号

from django.db import models

class provinceModel(models.Model):
    name = models.CharField(max_length=30)

    def __str__(self):
        return self.name

As said, it all works fine on local. 如前所述,在本地都可以正常工作。 On production, I'm trying the same and it gives me this error: 在生产中,我正在尝试相同的操作,它给了我这个错误:

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.

I'm guessing it's abstract... Since it's definitely installed (in settings.py). 我猜它是抽象的...因为它肯定已安装(在settings.py中)。

To make things right, I decided to toy around. 为了使事情变得正确,我决定玩转玩具。 I noticed even when removing all code there and just trying to edit the app using the django admin feature, it won't show up in admin either. 我注意到,即使在删除所有代码并尝试使用django admin功能编辑应用程序时,它也不会显示在admin中。

I'm pretty sure these two problems are related, and I am hoping someone came across sth similar or just knows what I'm supposed to do here. 我很确定这两个问题是相关的,我希望有人遇到类似的事情,或者只是知道我在这里应该做什么。 I start to get the feeling there's an internal conflict somewhere, Django is not telling me about. 我开始感觉到某个地方存在内部冲突,Django没有告诉我。 Since some models can be added to ForeignKeys, like the district one, but new models just won't work. 由于可以将某些模型(例如第一区)添加到ForeignKeys,但是新模型将不起作用。 I tried adding another new one too. 我也尝试添加另一个新的。

And yes, I did read the other related posts about app's not showing up. 是的,我确实阅读了有关应用程序未显示的其他相关文章。 They're registered in settings.py under INSTALLED_APPS. 它们已在INSTALLED_APPS下的settings.py中注册。 Any help is much appreciated! 任何帮助深表感谢!

3) 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) directory structure 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

Try that. 试试看 I answered you on IRC but you logged off right as i posted the answer. 我在IRC上回答了您,但您在我发布答案时就注销了。 If you're going to spam your SO problem all over the net, wait for an answer. 如果您要在整个网络上发送垃圾邮件,请等待答案。 I almost didn't chase you here. 我差点没在这里追你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM