Forums

adding new apps (tutorial part 2)

the tutorial claims you want:

"But where's our poll app? It's not displayed on the admin index page.

Just one thing to do: We need to tell the admin that Poll objects have an admin interface. To do this, create a file called admin.py in your polls directory, and edit it to look like this:"

from polls.models import Poll
from django.contrib import admin

admin.site.register(Poll)

This doesn't work.

What I found worked:

from models import Poll
from django.contrib import admin

admin.site.register(Poll)

Before I was getting a "can not find polls.models"

Where you import stuff from depends on how you've set your Python path. It's important to always know what your path is set to so you know where you're importing from.

Ya but if you follow the tutorial, you should have the directories in the same place

It's a matter of personal preference where you place the top-level of your path for Django projects. We chose a different preference as a default to the Django tutorial.

Deleting the polls from polls.models isn't the best way of fixing it. Depending on your preference, there are 2 ways that are better:

In your wsgi file, change the line

project_home = u'/home/JoeButy'

to

project_home = u'/home/JoeButy/mysite'

and

os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

to

os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

Then you can use the same import pattern that the Django tutorial uses.

Alternatively, you can just add 'mysite' in front of all the imports. So from polls.models import Poll becomes from mysite.polls.models import Poll

That's assuming that you have stuck to the Django quickstart default name of mysite, otherwise just use the name you chose instead of mysite, above.

ok. wow that was a great answer thanks glenn.