5

I'm new to Django and i've already come across a problem. I'm using Django 1.4.3 on OSX Mountain lion.

When I start a new app using

    django-admin.py startapp "name" 

the app is created and all the necessary files are within it (__Init__.py, models.py, tests.py, views.py). However, the admin.py file which should be automatically created is not in the app folder. Without it, i cannot edit my administrator site preferences.

Any ideas as to why this may be happening?

Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
Gpivovarov
  • 51
  • 1
  • 3
  • 1
    I don't recall `admin.py` being created automatically. There's nothing that can be put into it with a new app anyway since you need to have models for the admin to do anything. – Michael Mior Feb 14 '13 at 15:26
  • @Michael Mior That's strange. I'm going through to tutorial on the Django site and it says that as soon as i create a new app, the admin.py file should be there, but i'll look around – Gpivovarov Feb 14 '13 at 15:29
  • 1
    As a rule a thumb: "if file does not exist, create it". – jpic Feb 14 '13 at 16:42
  • 3
    not sure why people are so ornery about this topic. if a framework purports to create certain files and then fails to, it's hard to know if just creating one yourself you'll omit stubbing out the appropriate imports or whatever else the framework might have been doing for you. – Brian Sweeney Jun 11 '13 at 19:41

3 Answers3

8

You have to create the file manually since the django admin is disabled by default.

Instructions on what to put in admin.py are here.

Garrett Hyde
  • 5,409
  • 8
  • 49
  • 55
user1688936
  • 111
  • 2
  • 2
    https://docs.djangoproject.com/en/1.4/ref/contrib/admin/#modeladmin-objects for more specific instructions and the latest docs – Aidan Ewen Feb 14 '13 at 15:27
3

You are most likely reading the dev tutorial but using a stable release (currently 1.4.3). admin.py is created by startapp as of this commit which also updated the tutorial documentation but it won't make it into a stable release until 1.6.

Mark Lavin
  • 24,664
  • 5
  • 76
  • 70
2

Admin.py is not generated. In response to OP's to your comment on the post above:

From part 1 of the tutorial: https://docs.djangoproject.com/en/1.4/intro/tutorial01/

Let’s look at what startproject created:

mysite/
    manage.py
    mysite/
        __init__.py
        settings.py
        urls.py
        wsgi.py

And on part 2, under the section "Make the poll app modifiable in the admin" it says:

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)
Community
  • 1
  • 1
RyanBrady
  • 6,633
  • 4
  • 27
  • 32
  • 1
    Right, but when it asks to begin a new app, 'Poll', theres no Admin.py file. The tutorial says a lot about what to put into said Admin.py file but it doesn't seem to say where to create it or where to initiate it within Django. – Gpivovarov Feb 14 '13 at 19:53
  • 1
    On https://docs.djangoproject.com/en/1.4/intro/tutorial02/#activate-the-admin-site , there is a header that reads "Make the poll app modifiable in the admin" In it's text description below that it says, "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....... – RyanBrady Feb 14 '13 at 20:06