Django admin.site.register doesn't add my app admin
django, python
Solution
Check all of these:
There are seven steps in activating the Django admin site:
- Add 'django.contrib.admin' to your INSTALLED_APPS setting.
- The admin has four dependencies - django.contrib.auth, django.contrib.contenttypes, django.contrib.messages and django.contrib.sessions. If these applications are not in your INSTALLED_APPS list, add them.
- Add django.contrib.messages.context_processors.messages to TEMPLATE_CONTEXT_PROCESSORS and MessageMiddleware to MIDDLEWARE_CLASSES. (These are both active by default, so you only need to do this if you’ve manually tweaked the settings.)
- Determine which of your application’s models should be editable in the admin interface.
- For each of those models, optionally create a ModelAdmin class that encapsulates the customized admin functionality and options for that particular model.
- Instantiate an AdminSite and tell it about each of your models and ModelAdmin classes.
- Hook the AdminSite instance into your URLconf.
- Do you have all the other admin dependencies in your installed apps?
- Do you have `admin.autodiscover()` in your URLS.py?
Also, I think your code should look something more like this:
from projectname.appname.models import Appname
from django.contrib import admin
class AppnameAdmin(admin.ModelAdmin):
fieldsets = [various field sets and fields etc ]
admin.site.register(Appname,AppnameAdmin)
Problem
as a django newbie (I have some exprience with other python webframework like turbogears and bottle but exploring django) I'm trying to auto create the admin management for my app model in tha main URLS.py I have: edit: ``` from django.contrib import admin admin.autodiscover() ``` and after that: ``` urlpatterns = patterns('', url(r'^appname/',include('appname.urls')), url(r'^admin/',include(admin.site.urls)) ``` notice this is in the main urls.py and not in the app urls.py following the tutorial (which did work for me in the tutorial..) I created an 'admin.py' file in the appname folder and there: ``` from appname.models import Appname from django.contrib import admin class appnameAdmin(admin.ModelAdmin): fieldsets = [various field sets and fields etc ] admin.site.register(Appname,AppnameAdmin) ``` and in setting.py I have uncommented ``` 'django.contrib.admin' ``` I don't get any error in the commandline window and the basic admin screen does appear (auth and sites) I checked the imports in admin.py in the manage.py shell and everything seemed to work allright, I also tried commenting AppnameAdmin class out and registring just: ``` admin.site.register(Appname) ``` but that didn't work eith I'm guessing I'm missing something obvious - I'll be glad to help with that using django 1.4 + python 2.72