SaltyCrane Blog — Notes on JavaScript and web development

Django Blog Project #11: Migrating from Django 0.96 to SVN Trunk

I've been using the Django 0.96 release for this blog, but I've been thinking about switching to the SVN trunk version since it is recommended by the Django community. Django 1.0 alpha was released a couple weeks ago, so now seems like a good time to migrate.

Here are the changes I had to make. There were suprisingly few changes required-- probably because I'm not using a lot of the Django functionality. For a complete list of changes, see the Backwards-incompatible changes documentation.

Note, I am using trunk revision 8210. (2 weeks post Alpha).

Model changes

The admin definitions have been decoupled from the model definitions. Also, the prepopulate_from database field has been moved to the new admin class. See here for more information. Also maxlength was changed to max_length.

import re
from django.db import models
from django.contrib.auth.models import User
from django.contrib import admin

class Post(models.Model):
    author = models.ForeignKey(User)
    title = models.CharField(max_length=200)
    slug = models.SlugField(max_length=200,
    date_created = models.DateTimeField(auto_now_add=True)
    date_modified = models.DateTimeField(auto_now=True)
    tags = models.CharField(max_length=200, help_text="Space separated.")
    body = models.TextField()
    body_html = models.TextField(editable=False, blank=True)
    lc_count = models.IntegerField(default=0, editable=False)

    def get_tag_list(self):
        return re.split(" ", self.tags)

    def get_absolute_url(self):
        return "/blog/%d/%02d/%s/" % (self.date_created.year,

    def __str__(self):
        return self.title

    class Meta:
        ordering = ["-date_created"]

    class Admin:

class PostAdmin(admin.ModelAdmin):
    prepopulated_fields = {'slug': ('title',)}, PostAdmin)
Modify URLConf

See here for more information.

from django.conf.urls.defaults import *
from django.contrib import admin
from django.contrib.comments.models import FreeComment
from iwiwdsmi.myblogapp.views import *
from iwiwdsmi.feeds import *
from iwiwdsmi.views import *


feeds = {
    'latest': LatestPosts,

urlpatterns = patterns(
    (r'^site_media/(?P.*)$', 'django.views.static.serve', {'document_root': '/home/sofeng/src/django/iwiwdsmi/media'}),

    (r'^admin/', include('django.contrib.admin.urls')),
    (r'^feeds/(?P.*)/$', 'django.contrib.syndication.views.feed', 
     {'feed_dict': feeds}),
    (r'^comments/', include('django.contrib.comments.urls.comments')),
    (r'^myview1/$', myview1),
    (r'^$', rootview),
    (r'^blog/$', frontpage),
    (r'^blog/(\d{4,4})/(\d{2,2})/([\w\-]+)/$', singlepost),
    (r'^blog/(\d{4,4})/$', yearview),
    (r'^blog/(\d{4,4})/(\d{2,2})/$', monthview),
    (r'^blog/tag/([\w\-]+)/$', tagview),
Use the safe template filter

In the Django templates, Django SVN now escapes HTML by default to protect against cross-site scripting. To display my HTML blog posts, I needed to use the safe filter.

Excerpt from ~/src/django/myblogsite/templates/listpage.html:
    {{ post.body|safe|truncatewords_html:"50" }}
Use new admin templates

Finally, I copied over the new Django SVN templates from trunk/django/contrib/admin/templates.