[Answered ]-Django 1.5.1 – Admin.py missing while running startapp

2👍

You have to create an admin.py file.

0👍

you don’t necessarily need an admin.py file,

just import the admin module in your models.py file,

from django.contrib import admin

and for each model do the following:

admin.site.register(model1)
admin.site.register(model2)

However, this is not best practice, but since it’s just a tutorial, it will work.

You also need to uncoment the relevant lines in the urls.py file

👤Bit68

0👍

I think I had the same frustrations following the DjangoProject tutorial – however, when I cross-referenced it with with the DjangoBook tutorial (for the same version, I believe, 1.5.1), I found that an admin.py file was not necessarily created after a python manage.py startapp xyz command — moreover, I also uncommented all of the admin options in urls.py, views.py, and settings.py – so a bit of a mix of what Neal and Ibrahim said

👤AGHz

0👍

You have to create your own admin.py file in the app if you want it. Indeed, this file is optionnal and isn’t created by startapp.

If you want a default template to begin your admin.py, it should be:

from django.contrib import admin
from models import Model1, Model2

class Model2Admin(admin.ModelAdmin):
    list_display   = ('title', 'content', 'date')
    # Just an example, chekc docs and tutorials for more info.

admin.site.register(Model1)
admin.site.register(Model2, Model2Admin)

0👍

The reason there is no default admin.py is because you don’t have any models yet when you create your new application; so there is nothing to add to the admin section.

Further, you may not want to admin all the models in your application; or you may be creating an application that does not need any admin hookups; or you may not be using the admin application at all in your project.

Since django cannot decide this for you, there is no default admin.py generated.

To create one, if you are following the tutorial – simply keep reading and in part two you’ll create the admin.py file when you learn about the admin contrib app and how to integrate it with your custom models.

Leave a comment