Django admin changes in SVN trunk

Recently in Django SVN trunk all admin interface changed to newforms. It doesn't have backward compatibility, so I provide some hints to upgrade existing Django applications.

There are at least 3 steps for upgrading:

  • Update to follow new admin URLs.
  • Update admin classes.
  • Change all newforms imports.

Update to follow new admin URLs.

Initially looks like:

urlpatterns = patterns('',
    (r'^admin/', include('django.contrib.admin.urls')),

Now it should look like:

from django.contrib import admin
urlpatterns = patterns('',
   (r'^admin/doc/', include('django.contrib.admindocs.urls')),

Update admin classes.

Initially admin classes were a part of model classes. Now they should be moved to independent classes.

If a model had empty class:

class Model1(models.Model):
   class Admin:

Now it is enough just register a model with admin site:

from django.contrib import admin

For non-empty admin classes like this:

class Model1(models.Model):
   class Admin:
       search_fields = ('title',)

Now it is required to declare independent class:

from django.contrib import admin
class Model1Admin(admin.ModelAdmin):
   search_fields = ('title',), Model1Admin)

Please notice that all admin classes can be (and should be in most cases) declared in file now (in the same directory there are located).

Change all newforms imports.

These changes are not required, but without them prints DeprecatedWarning. The change is simple.

The original import:

from django import newforms as forms

The new one:

from django import forms

Good luck with updating!


Popular posts from this blog

Trac Ticket Workflow

Introduction to ReviewBoard

Python vs JS vs PHP for embedded systems