comparison content/Coding/025-upgrading-django1.5.rst @ 4:7ce6393e6d30

Adding converted blog posts from old blog.
author Brian Neal <bgneal@gmail.com>
date Thu, 30 Jan 2014 21:45:03 -0600
parents
children 49bebfa6f9d3
comparison
equal deleted inserted replaced
3:c3115da3ff73 4:7ce6393e6d30
1 Upgrading to Django 1.5
2 #######################
3
4 :date: 2013-08-29 19:30
5 :tags: Django
6 :slug: upgrading-to-django-1.5
7 :author: Brian Neal
8
9 Upgrading to Django 1.5
10 =======================
11
12 `Django`_ 1.5 came out a while ago, and I finally got around to upgrading two
13 of my largest sites. I thought I would make a list of what I changed at a high
14 level for my own reference. Perhaps someone else may find it useful as well.
15
16 In any event, I highly recommend you read the excellent `release notes`_ and
17 `deprecation timeline`_. I also recommend you run with warnings turned on::
18
19 $ python -Wall manage.py runserver
20
21 This will help you flag down issues in your code. If you aren't sure where
22 a warning is coming from, you can turn warnings into exceptions and get
23 a traceback (see the Python docs on the warnings_ library). Another trick is to
24 put a pdb_ breakpoint in the Django code before or after the warning, then you
25 can examine the call stack with the ``w`` command.
26
27 Upgrading Issues
28 ================
29
30 Here are the issues that I ran into. Of course you may have a very different
31 experience depending on what features of Django you used and the details of
32 your site.
33
34 #. **Replace occurrences of Django's simplejson with json**. The Django team
35 deprecated their version of the json library since they had dropped support
36 for older versions of Python.
37
38 #. **select_related's depth argument is deprecated**. Instead of using
39 ``depth`` I had to explictly name which relationships to follow.
40
41 #. **The cleanup management command is now called clearsessions**. I have
42 a Celery_ task I had to update because of this name change.
43
44 #. **Remove my {% load url from future %} tags**. Long ago I had converted to
45 the newer ``url`` tag behavior by using this tag. Since this is now the
46 current behavior I could remove all of these tags.
47
48 #. **The LOGIN_* settings now accept URL names**. These settings can now accept
49 URL names which allows me to be more DRY (Don't Repeat Yourself). I no
50 longer have to maintain URL patterns in two places.
51
52 #. **Management commands should use self.stdout, etc. for output**. I'm not
53 sure if this is required, but it makes it easier to test your management
54 commands.
55
56 #. **slugify is now available at django.utils.text**. I was doing something
57 kind of hacky by invoking the slugify template filter in Python code. Now
58 this slugify code is more naturally available as a free Python function
59 without the template filter baggage.
60
61 #. **Remove all references to django.contrib.markup**. Django decided not to be
62 so tightly coupled to various third party markup languages. I can see their
63 reasoning, as it does add to their maintenance burden, but it is kind of
64 inconvenient if you already relied on it. Fortunately I had a while ago
65 stopped relying on the Markdown filter and had used a custom solution.
66 Seeing this issue in the release notes caused me to go looking through my
67 code and I found some unused templates and ``INSTALLED_APPS`` setting that
68 I could remove. On my second site, I had one tiny usage of the Textile
69 filter that I decided to just get rid of since it was hardly worth carrying
70 the dependency for. I wrote a quick and dirty management command to convert
71 the database from storing Textile markup to HTML and I was done.
72
73 #. **localflavor is deprecated in preferece to a third party app**. I was using
74 some US state fields in a few models. All I had to do was pip_ install
75 `django-localflavor`_, fix up some imports, update my requirements files,
76 and I was good.
77
78 #. **Function-based generic views are now gone**. A third party application
79 I am using made use of the old function-based generic views. These have been
80 replaced with the newer class-based generic views. Luckily I wasn't actually
81 using the views in this application, I am only relying on it's models and
82 utilities. In this case I simply removed the inclusion of the application's
83 ``urls.py`` and all was well. The application is no longer maintained so
84 I would have had to port to the class-based views if I had needed them.
85
86 #. **The adminmedia template tags library is now gone**. I wasn't actually
87 using this anymore, but I had a template that was still loading it. This
88 cruft was removed.
89
90 What I didn't do
91 ================
92
93 Django 1.5's largest new feature is probably its support for a `configurable
94 User model`_. This impacts my largest site, and I wasn't quite sure how to
95 proceed on this front. This is the only issue I feel like Django threw me under
96 the bus on. Fortunately, the ``get_profile()`` and ``AUTH_PROFILE_MODULE``
97 stuff will not be removed until Django 1.7. In addition, the author of the
98 South_ library is developing model migration support which will also land in
99 Django 1.7. Thus there is some time to sort this out, and I'm hoping Django
100 will have some tutorials or docs on how to migrate away from the old
101 ``AUTH_PROFILE_MODULE`` scheme.
102
103 Conclusion
104 ==========
105
106 The upgrade process went smoother and quicker than I thought thanks to the
107 excellent release notes and the Django team's use of Python warnings to flag
108 deprecated features.
109
110
111 .. _Django: https://www.djangoproject.com/
112 .. _release notes: https://docs.djangoproject.com/en/1.5/releases/1.5/
113 .. _deprecation timeline: https://docs.djangoproject.com/en/1.5/internals/deprecation/
114 .. _warnings: http://docs.python.org/library/warnings.html
115 .. _pdb: http://docs.python.org/library/pdb.html
116 .. _Celery: http://www.celeryproject.org/
117 .. _pip: http://www.pip-installer.org/en/latest/
118 .. _django-localflavor: https://pypi.python.org/pypi/django-localflavor
119 .. _configurable user model: https://docs.djangoproject.com/en/1.5/topics/auth/customizing/#auth-custom-user
120 .. _South: http://south.aeracode.org/