Upgrading to Django 1.0
I have build over 25 small and big Django web apps or web sites. Some of them are simple less than a few hours-to-build web sites such as this blog site. But quite a few of them have required weeks to finish.
Django went through a major face lift or shall we say “gut-churning” from pre-10 alpha stages to 1.0.
Since it was a long weekend here in India, I took the job of upgrading or updating these sites.
After upgrading around ten sites, I discovered that there are quite a few things which I did which were common to all these sites. Here I list a few of them. I will update them again as soon as I finish the entire laundry list, a task which I presume will take me a week more considering the heavy schedule the week ahead.
1) admin related in urls.py
Django’s built-in admin module is cool, and except two web apps that I have written, almost all of the others use it.
The first place you need to go is go and fix the admin stuff in urls.py
After removing all references to admin from the urls.py I added this piece of code. It works most of the time.
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^admin/(.*)', admin.site.root),
)
Make sure rest of the places where urlpatterns are required you useurlpatterns += patterns('',………
2) Explicitly bringing apps inside the admin
One of the cool things about the admin, prior to 1.0, was that to get the model activated in the admin, all you needed to write at end of the class instantiated out of models.Model was an inner class called Admin, and you could actually get a CRUD app ready in minutes.
Now you need to explicitly register each application. It is always better to write a separate admin.py file.
3) Remove deprecated keywords
I had to do a lot of code cleanup, there were a quite a few instances of ‘maxlength’. I used global replacement in most cases, and it works. Similarly remember to remove all references to newforms. There are many others such as using of prepopulated_from in SlugFields.
4) Cleanup Comments
The new comments framework will force a number of changes.
Refer Django docs on the same.
Ensure that you add this in urls.py.
(r'^comments/', include('django.contrib.comments.urls')),
Remove any references to FreeComment.
In templates remove free from the different templatetags. Hence get_free_comment_list becomes get_comment_list.
Also use render_comment_form to create the form.
Comment