简体   繁体   中英

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. 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

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

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).

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.

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. Since some models can be added to ForeignKeys, like the district one, but new models just won't work. 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. Any help is much appreciated!

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

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. If you're going to spam your SO problem all over the net, wait for an answer. I almost didn't chase you here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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