Reputation: 2078
Django keeps telling me this, even after recoding everything, and I cannot seem to find help on Google. Project folder is as follows:
$ tree
.
|-- project
| |-- __init__.py
| |-- __init__.pyc
| |-- settings.py
| |-- settings.py~
| |-- settings.pyc
| |-- urls.py
| |-- urls.pyc
| |-- wsgi.py
| `-- wsgi.pyc
|-- city
| |-- __init__.py
| |-- __init__.pyc
| |-- models.py
| |-- models.pyc
| |-- tests.py
| `-- views.py
|-- course
| |-- __init__.py
| |-- __init__.pyc
| |-- models.py
| |-- models.pyc
| |-- tests.py
| `-- views.py
|-- manage.py
|-- perk
| |-- __init__.py
| |-- __init__.pyc
| |-- models.py
| |-- models.pyc
| |-- static
| |-- tests.py
| `-- views.py
|-- preuniversity
| |-- __init__.py
| |-- __init__.pyc
| |-- models.py
| |-- models.py~
| |-- models.pyc
| |-- tests.py
| `-- views.py
`-- user
|-- __init__.py
|-- __init__.pyc
|-- models.py
|-- models.py~
|-- models.pyc
|-- tests.py
`-- views.py
The structure has not been changed, neither did I modify anything except for models.py, which is:
$ cat city/models.py
from django.db import models
class State(models.Model):
acronym = models.CharField(max_length=2)
name = models.CharField(max_length=32)
class City(models.Model):
name = models.CharField(max_length=32)
state = models.ForeignKey(State)
I'm just following Django tutorial, no more and no less, and there is no solution. I used startapp on every app (and didn't just copy&paste from another) and the app names are there in settings.py.
If I remove every reference to city (foreign keys, imports and remove from installed_apps) it complains about the next app (course).
Upvotes: 0
Views: 1252
Reputation: 2078
So I managed to fix the errors. Maybe I forgot some important info on the question but here is the explanation:
I downloaded PyDev for Eclipse and rebuilt the project from scratch. So, when I was writing the imports, Eclipse complained it was not right. Well, I went back to Django tutorial and there is import city
, so I was right. I accepted the suggestion from Eclipse and it changed to from city.models import City
and it went ok. So I tested with the old project and changed every import, and it validated and synced with no errors.
Now I'm very confused, how could Django documentation be wrong? Or is this Python-version or distro peculiarity? Well, nevermind, it is now working. Thanks everybody :P
Upvotes: 0
Reputation: 1485
I assume you are using django 1.4 or later because of what is in your project folder.
Did you create the top-level directory with django-admin.py startproject
? I don't see the __init__.py
file at the top level, although the project
directory with settings.py
and urls.py
is there. Create an empty file called __init__.py
at the top level (sibling of manage.py
) and see if that helps.
Upvotes: 1
Reputation: 1182
Put your city (files which you want to import) in root dir of main application. If IDE(PyCharm for an example) wont worry about import this module - than the problem was in paths.
I've smashed with this problem at once. And the problem paths were.
Upvotes: 0