Upgrading from Django 0.96 to 1.0 Alpha

This post is by no means up to the standard of the official Django 1.0 alpha release notes; it merely details what I had to do to get a Django 0.96 site working under Django 1.0 alpha.

First, update your Django code. Mine's under svn, but svn up spewed an error, so i deleted the folder and checked out Django again.

Next, open the models.py file in each of your applications. Remove the Admin classes from each model. Also, remove the prepopulate_from parameters from fields.

Now open urls.py, and remove the old entry:
# Uncomment this for admin:
# (r'^admin/', include('django.contrib.admin.urls')),

and replace it with
(r'^admin/doc/', include('django.contrib.admindocs.urls')),
(r'^admin/(.*)', admin.site.root),

(the first line enables admin documentation).

Also, add to the top of the urls.py file:
from django.contrib import admin
admin.autodiscover()

admin.autodiscover() will look for an admin.py module in each installed app in INSTALLED_APPS and incorperate it into an admin page.

Now, for each app that we want admin functionality for, make its admin.py
The bare minimum you can do is simply inherit from the class they provide. You can do it like so:
Extract from appname/admin.py:

from django.contrib import admin
from breeze.web.models import *

class CountryAdmin(admin.ModelAdmin):
pass
admin.site.register(Country, CountryAdmin)

class UserLevelAdmin(admin.ModelAdmin):
pass
admin.site.register(UserLevel, UserLevelAdmin)

class UserProfileAdmin(admin.ModelAdmin):
prepopulated_fields = {"slug": ("name",)} # Populates slug field from name field
admin.site.register(UserProfile, UserProfileAdmin)

Now, when you type ./manage.py runserver it should just work.
Django 1.0 newforms-admin screenshot

Of course you can do lots more magic , see the Django Admin Documentation for more things, such as inline displaying of related tables. You can even make multiple admin classes.

Posted 30th July 2008 in Computer, with 0 comments

Digg!

comments


  1. (optional)