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 urls.py to follow new admin URLs.
- Update admin classes.
- Change all newforms imports.
Update urls.py to follow new admin URLs.
Initially urls.py looks like:
urlpatterns = patterns('', (r'^admin/', include('django.contrib.admin.urls')), )
Now it should look like:
from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', (r'^admin/doc/', include('django.contrib.admindocs.urls')), (r'^admin/(.*)', admin.site.root), )
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: pass
Now it is enough just register a model with admin site:
from django.contrib import admin admin.site.register(Model1)
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',) admin.site.register(Model1, Model1Admin)
Please notice that all admin classes can be (and should be in most cases) declared in admin.py file now (in the same directory there are models.py located).
Change all newforms imports.
These changes are not required, but without them manage.py 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!