|
1 ======================== |
|
2 Django 1.1 release notes |
|
3 ======================== |
|
4 |
|
5 |
|
6 July 29, 2009 |
|
7 |
|
8 Welcome to Django 1.1! |
|
9 |
|
10 Django 1.1 includes a number of nifty `new features`_, lots of bug |
|
11 fixes, and an easy upgrade path from Django 1.0. |
|
12 |
|
13 .. _new features: `What's new in Django 1.1`_ |
|
14 |
|
15 .. _backwards-incompatible-changes-1.1: |
|
16 |
|
17 Backwards-incompatible changes in 1.1 |
|
18 ===================================== |
|
19 |
|
20 Django has a policy of :doc:`API stability </misc/api-stability>`. This means |
|
21 that, in general, code you develop against Django 1.0 should continue to work |
|
22 against 1.1 unchanged. However, we do sometimes make backwards-incompatible |
|
23 changes if they're necessary to resolve bugs, and there are a handful of such |
|
24 (minor) changes between Django 1.0 and Django 1.1. |
|
25 |
|
26 Before upgrading to Django 1.1 you should double-check that the following |
|
27 changes don't impact you, and upgrade your code if they do. |
|
28 |
|
29 Changes to constraint names |
|
30 --------------------------- |
|
31 |
|
32 Django 1.1 modifies the method used to generate database constraint names so |
|
33 that names are consistent regardless of machine word size. This change is |
|
34 backwards incompatible for some users. |
|
35 |
|
36 If you are using a 32-bit platform, you're off the hook; you'll observe no |
|
37 differences as a result of this change. |
|
38 |
|
39 However, **users on 64-bit platforms may experience some problems** using the |
|
40 :djadmin:`reset` management command. Prior to this change, 64-bit platforms |
|
41 would generate a 64-bit, 16 character digest in the constraint name; for |
|
42 example:: |
|
43 |
|
44 ALTER TABLE myapp_sometable ADD CONSTRAINT object_id_refs_id_5e8f10c132091d1e FOREIGN KEY ... |
|
45 |
|
46 Following this change, all platforms, regardless of word size, will generate a |
|
47 32-bit, 8 character digest in the constraint name; for example:: |
|
48 |
|
49 ALTER TABLE myapp_sometable ADD CONSTRAINT object_id_refs_id_32091d1e FOREIGN KEY ... |
|
50 |
|
51 As a result of this change, you will not be able to use the :djadmin:`reset` |
|
52 management command on any table made by a 64-bit machine. This is because the |
|
53 the new generated name will not match the historically generated name; as a |
|
54 result, the SQL constructed by the reset command will be invalid. |
|
55 |
|
56 If you need to reset an application that was created with 64-bit constraints, |
|
57 you will need to manually drop the old constraint prior to invoking |
|
58 :djadmin:`reset`. |
|
59 |
|
60 Test cases are now run in a transaction |
|
61 --------------------------------------- |
|
62 |
|
63 Django 1.1 runs tests inside a transaction, allowing better test performance |
|
64 (see `test performance improvements`_ for details). |
|
65 |
|
66 This change is slightly backwards incompatible if existing tests need to test |
|
67 transactional behavior, if they rely on invalid assumptions about the test |
|
68 environment, or if they require a specific test case ordering. |
|
69 |
|
70 For these cases, :class:`~django.test.TransactionTestCase` can be used instead. |
|
71 This is a just a quick fix to get around test case errors revealed by the new |
|
72 rollback approach; in the long-term tests should be rewritten to correct the |
|
73 test case. |
|
74 |
|
75 .. _removed-setremoteaddrfromforwardedfor-middleware: |
|
76 |
|
77 Removed ``SetRemoteAddrFromForwardedFor`` middleware |
|
78 ---------------------------------------------------- |
|
79 |
|
80 For convenience, Django 1.0 included an optional middleware class -- |
|
81 ``django.middleware.http.SetRemoteAddrFromForwardedFor`` -- which updated the |
|
82 value of ``REMOTE_ADDR`` based on the HTTP ``X-Forwarded-For`` header commonly |
|
83 set by some proxy configurations. |
|
84 |
|
85 It has been demonstrated that this mechanism cannot be made reliable enough for |
|
86 general-purpose use, and that (despite documentation to the contrary) its |
|
87 inclusion in Django may lead application developers to assume that the value of |
|
88 ``REMOTE_ADDR`` is "safe" or in some way reliable as a source of authentication. |
|
89 |
|
90 While not directly a security issue, we've decided to remove this middleware |
|
91 with the Django 1.1 release. It has been replaced with a class that does nothing |
|
92 other than raise a ``DeprecationWarning``. |
|
93 |
|
94 If you've been relying on this middleware, the easiest upgrade path is: |
|
95 |
|
96 * Examine `the code as it existed before it was removed`__. |
|
97 |
|
98 * Verify that it works correctly with your upstream proxy, modifying |
|
99 it to support your particular proxy (if necessary). |
|
100 |
|
101 * Introduce your modified version of ``SetRemoteAddrFromForwardedFor`` as a |
|
102 piece of middleware in your own project. |
|
103 |
|
104 __ http://code.djangoproject.com/browser/django/trunk/django/middleware/http.py?rev=11000#L33 |
|
105 |
|
106 Names of uploaded files are available later |
|
107 ------------------------------------------- |
|
108 |
|
109 .. currentmodule:: django.db.models |
|
110 |
|
111 In Django 1.0, files uploaded and stored in a model's :class:`FileField` were |
|
112 saved to disk before the model was saved to the database. This meant that the |
|
113 actual file name assigned to the file was available before saving. For example, |
|
114 it was available in a model's pre-save signal handler. |
|
115 |
|
116 In Django 1.1 the file is saved as part of saving the model in the database, so |
|
117 the actual file name used on disk cannot be relied on until *after* the model |
|
118 has been saved. |
|
119 |
|
120 Changes to how model formsets are saved |
|
121 --------------------------------------- |
|
122 |
|
123 .. currentmodule:: django.forms.models |
|
124 |
|
125 In Django 1.1, :class:`BaseModelFormSet` now calls :meth:`ModelForm.save()`. |
|
126 |
|
127 This is backwards-incompatible if you were modifying ``self.initial`` in a model |
|
128 formset's ``__init__``, or if you relied on the internal ``_total_form_count`` |
|
129 or ``_initial_form_count`` attributes of BaseFormSet. Those attributes are now |
|
130 public methods. |
|
131 |
|
132 Fixed the ``join`` filter's escaping behavior |
|
133 --------------------------------------------- |
|
134 |
|
135 The :ttag:`join` filter no longer escapes the literal value that is |
|
136 passed in for the connector. |
|
137 |
|
138 This is backwards incompatible for the special situation of the literal string |
|
139 containing one of the five special HTML characters. Thus, if you were writing |
|
140 ``{{ foo|join:"&" }}``, you now have to write ``{{ foo|join:"&" }}``. |
|
141 |
|
142 The previous behavior was a bug and contrary to what was documented |
|
143 and expected. |
|
144 |
|
145 Permanent redirects and the ``redirect_to()`` generic view |
|
146 ---------------------------------------------------------- |
|
147 |
|
148 Django 1.1 adds a ``permanent`` argument to the |
|
149 :func:`django.views.generic.simple.redirect_to()` view. This is technically |
|
150 backwards-incompatible if you were using the ``redirect_to`` view with a |
|
151 format-string key called 'permanent', which is highly unlikely. |
|
152 |
|
153 .. _deprecated-features-1.1: |
|
154 |
|
155 Features deprecated in 1.1 |
|
156 ========================== |
|
157 |
|
158 One feature has been marked as deprecated in Django 1.1: |
|
159 |
|
160 * You should no longer use ``AdminSite.root()`` to register that admin |
|
161 views. That is, if your URLconf contains the line:: |
|
162 |
|
163 (r'^admin/(.*)', admin.site.root), |
|
164 |
|
165 You should change it to read:: |
|
166 |
|
167 (r'^admin/', include(admin.site.urls)), |
|
168 |
|
169 You should begin to remove use of this feature from your code immediately. |
|
170 |
|
171 ``AdminSite.root`` will raise a ``PendingDeprecationWarning`` if used in |
|
172 Django 1.1. This warning is hidden by default. In Django 1.2, this warning will |
|
173 be upgraded to a ``DeprecationWarning``, which will be displayed loudly. Django |
|
174 1.3 will remove ``AdminSite.root()`` entirely. |
|
175 |
|
176 For more details on our deprecation policies and strategy, see |
|
177 :doc:`/internals/release-process`. |
|
178 |
|
179 What's new in Django 1.1 |
|
180 ======================== |
|
181 |
|
182 Quite a bit: since Django 1.0, we've made 1,290 code commits, fixed 1,206 bugs, |
|
183 and added roughly 10,000 lines of documentation. |
|
184 |
|
185 The major new features in Django 1.1 are: |
|
186 |
|
187 ORM improvements |
|
188 ---------------- |
|
189 |
|
190 .. currentmodule:: django.db.models |
|
191 |
|
192 Two major enhancements have been added to Django's object-relational mapper |
|
193 (ORM): aggregate support, and query expressions. |
|
194 |
|
195 Aggregate support |
|
196 ~~~~~~~~~~~~~~~~~ |
|
197 |
|
198 It's now possible to run SQL aggregate queries (i.e. ``COUNT()``, ``MAX()``, |
|
199 ``MIN()``, etc.) from within Django's ORM. You can choose to either return the |
|
200 results of the aggregate directly, or else annotate the objects in a |
|
201 :class:`QuerySet` with the results of the aggregate query. |
|
202 |
|
203 This feature is available as new :meth:`QuerySet.aggregate()`` and |
|
204 :meth:`QuerySet.annotate()`` methods, and is covered in detail in :doc:`the ORM |
|
205 aggregation documentation </topics/db/aggregation>`. |
|
206 |
|
207 Query expressions |
|
208 ~~~~~~~~~~~~~~~~~ |
|
209 |
|
210 Queries can now refer to a another field on the query and can traverse |
|
211 relationships to refer to fields on related models. This is implemented in the |
|
212 new :class:`F` object; for full details, including examples, consult the |
|
213 :ref:`documentation for F expressions <query-expressions>`. |
|
214 |
|
215 Model improvements |
|
216 ------------------ |
|
217 |
|
218 A number of features have been added to Django's model layer: |
|
219 |
|
220 "Unmanaged" models |
|
221 ~~~~~~~~~~~~~~~~~~ |
|
222 |
|
223 You can now control whether or not Django manages the life-cycle of the database |
|
224 tables for a model using the :attr:`~Options.managed` model option. This |
|
225 defaults to ``True``, meaning that Django will create the appropriate database |
|
226 tables in :djadmin:`syncdb` and remove them as part of the :djadmin:`reset` |
|
227 command. That is, Django *manages* the database table's lifecycle. |
|
228 |
|
229 If you set this to ``False``, however, no database table creating or deletion |
|
230 will be automatically performed for this model. This is useful if the model |
|
231 represents an existing table or a database view that has been created by some |
|
232 other means. |
|
233 |
|
234 For more details, see the documentation for the :attr:`~Options.managed` |
|
235 option. |
|
236 |
|
237 Proxy models |
|
238 ~~~~~~~~~~~~ |
|
239 |
|
240 You can now create :ref:`proxy models <proxy-models>`: subclasses of existing |
|
241 models that only add Python-level (rather than database-level) behavior and |
|
242 aren't represented by a new table. That is, the new model is a *proxy* for some |
|
243 underlying model, which stores all the real data. |
|
244 |
|
245 All the details can be found in the :ref:`proxy models documentation |
|
246 <proxy-models>`. This feature is similar on the surface to unmanaged models, |
|
247 so the documentation has an explanation of :ref:`how proxy models differ from |
|
248 unmanaged models <proxy-vs-unmanaged-models>`. |
|
249 |
|
250 Deferred fields |
|
251 ~~~~~~~~~~~~~~~ |
|
252 |
|
253 In some complex situations, your models might contain fields which could |
|
254 contain a lot of data (for example, large text fields), or require expensive |
|
255 processing to convert them to Python objects. If you know you don't need those |
|
256 particular fields, you can now tell Django not to retrieve them from the |
|
257 database. |
|
258 |
|
259 You'll do this with the new queryset methods |
|
260 :meth:`~django.db.models.QuerySet.defer` and |
|
261 :meth:`~django.db.models.QuerySet.only`. |
|
262 |
|
263 Testing improvements |
|
264 -------------------- |
|
265 |
|
266 A few notable improvements have been made to the :doc:`testing framework |
|
267 </topics/testing>`. |
|
268 |
|
269 Test performance improvements |
|
270 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
271 |
|
272 .. currentmodule:: django.test |
|
273 |
|
274 Tests written using Django's :doc:`testing framework </topics/testing>` now run |
|
275 dramatically faster (as much as 10 times faster in many cases). |
|
276 |
|
277 This was accomplished through the introduction of transaction-based tests: when |
|
278 using :class:`django.test.TestCase`, your tests will now be run in a transaction |
|
279 which is rolled back when finished, instead of by flushing and re-populating the |
|
280 database. This results in an immense speedup for most types of unit tests. See |
|
281 the documentation for :class:`TestCase` and :class:`TransactionTestCase` for a |
|
282 full description, and some important notes on database support. |
|
283 |
|
284 Test client improvements |
|
285 ------------------------ |
|
286 |
|
287 .. currentmodule:: django.test.client |
|
288 |
|
289 A couple of small -- but highly useful -- improvements have been made to the |
|
290 test client: |
|
291 |
|
292 * The test :class:`Client` now can automatically follow redirects with the |
|
293 ``follow`` argument to :meth:`Client.get` and :meth:`Client.post`. This |
|
294 makes testing views that issue redirects simpler. |
|
295 |
|
296 * It's now easier to get at the template context in the response returned |
|
297 the test client: you'll simply access the context as |
|
298 ``request.context[key]``. The old way, which treats ``request.context`` as |
|
299 a list of contexts, one for each rendered template in the inheritance |
|
300 chain, is still available if you need it. |
|
301 |
|
302 New admin features |
|
303 ------------------ |
|
304 |
|
305 Django 1.1 adds a couple of nifty new features to Django's admin interface: |
|
306 |
|
307 Editable fields on the change list |
|
308 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
309 |
|
310 You can now make fields editable on the admin list views via the new |
|
311 :ref:`list_editable <admin-list-editable>` admin option. These fields will show |
|
312 up as form widgets on the list pages, and can be edited and saved in bulk. |
|
313 |
|
314 Admin "actions" |
|
315 ~~~~~~~~~~~~~~~ |
|
316 |
|
317 You can now define :doc:`admin actions </ref/contrib/admin/actions>` that can |
|
318 perform some action to a group of models in bulk. Users will be able to select |
|
319 objects on the change list page and then apply these bulk actions to all |
|
320 selected objects. |
|
321 |
|
322 Django ships with one pre-defined admin action to delete a group of objects in |
|
323 one fell swoop. |
|
324 |
|
325 Conditional view processing |
|
326 --------------------------- |
|
327 |
|
328 Django now has much better support for :doc:`conditional view processing |
|
329 </topics/conditional-view-processing>` using the standard ``ETag`` and |
|
330 ``Last-Modified`` HTTP headers. This means you can now easily short-circuit |
|
331 view processing by testing less-expensive conditions. For many views this can |
|
332 lead to a serious improvement in speed and reduction in bandwidth. |
|
333 |
|
334 URL namespaces |
|
335 -------------- |
|
336 |
|
337 Django 1.1 improves :ref:`named URL patterns <naming-url-patterns>` with the |
|
338 introduction of URL "namespaces." |
|
339 |
|
340 In short, this feature allows the same group of URLs, from the same application, |
|
341 to be included in a Django URLConf multiple times, with varying (and potentially |
|
342 nested) named prefixes which will be used when performing reverse resolution. In |
|
343 other words, reusable applications like Django's admin interface may be |
|
344 registered multiple times without URL conflicts. |
|
345 |
|
346 For full details, see :ref:`the documentation on defining URL namespaces |
|
347 <topics-http-defining-url-namespaces>`. |
|
348 |
|
349 GeoDjango |
|
350 --------- |
|
351 |
|
352 In Django 1.1, GeoDjango_ (i.e. ``django.contrib.gis``) has several new |
|
353 features: |
|
354 |
|
355 * Support for SpatiaLite_ -- a spatial database for SQLite -- as a spatial |
|
356 backend. |
|
357 |
|
358 * Geographic aggregates (``Collect``, ``Extent``, ``MakeLine``, ``Union``) |
|
359 and ``F`` expressions. |
|
360 |
|
361 * New ``GeoQuerySet`` methods: ``collect``, ``geojson``, and |
|
362 ``snap_to_grid``. |
|
363 |
|
364 * A new list interface methods for ``GEOSGeometry`` objects. |
|
365 |
|
366 For more details, see the `GeoDjango documentation`_. |
|
367 |
|
368 .. _geodjango: http://geodjango.org/ |
|
369 .. _spatialite: http://www.gaia-gis.it/spatialite/ |
|
370 .. _geodjango documentation: http://geodjango.org/docs/ |
|
371 |
|
372 Other improvements |
|
373 ------------------ |
|
374 |
|
375 Other new features and changes introduced since Django 1.0 include: |
|
376 |
|
377 * The :doc:`CSRF protection middleware </ref/contrib/csrf>` has been split into |
|
378 two classes -- ``CsrfViewMiddleware`` checks incoming requests, and |
|
379 ``CsrfResponseMiddleware`` processes outgoing responses. The combined |
|
380 ``CsrfMiddleware`` class (which does both) remains for |
|
381 backwards-compatibility, but using the split classes is now recommended in |
|
382 order to allow fine-grained control of when and where the CSRF processing |
|
383 takes place. |
|
384 |
|
385 * :func:`~django.core.urlresolvers.reverse` and code which uses it (e.g., the |
|
386 ``{% url %}`` template tag) now works with URLs in Django's administrative |
|
387 site, provided that the admin URLs are set up via ``include(admin.site.urls)`` |
|
388 (sending admin requests to the ``admin.site.root`` view still works, but URLs |
|
389 in the admin will not be "reversible" when configured this way). |
|
390 |
|
391 * The ``include()`` function in Django URLconf modules can now accept sequences |
|
392 of URL patterns (generated by ``patterns()``) in addition to module names. |
|
393 |
|
394 * Instances of Django forms (see :doc:`the forms overview </topics/forms/index>`) |
|
395 now have two additional methods, ``hidden_fields()`` and ``visible_fields()``, |
|
396 which return the list of hidden -- i.e., ``<input type="hidden">`` -- and |
|
397 visible fields on the form, respectively. |
|
398 |
|
399 * The ``redirect_to`` generic view (see :doc:`the generic views documentation |
|
400 </ref/generic-views>`) now accepts an additional keyword argument |
|
401 ``permanent``. If ``permanent`` is ``True``, the view will emit an HTTP |
|
402 permanent redirect (status code 301). If ``False``, the view will emit an HTTP |
|
403 temporary redirect (status code 302). |
|
404 |
|
405 * A new database lookup type -- ``week_day`` -- has been added for ``DateField`` |
|
406 and ``DateTimeField``. This type of lookup accepts a number between 1 (Sunday) |
|
407 and 7 (Saturday), and returns objects where the field value matches that day |
|
408 of the week. See :ref:`the full list of lookup types <field-lookups>` for |
|
409 details. |
|
410 |
|
411 * The ``{% for %}`` tag in Django's template language now accepts an optional |
|
412 ``{% empty %}`` clause, to be displayed when ``{% for %}`` is asked to loop |
|
413 over an empty sequence. See :doc:`the list of built-in template tags |
|
414 </ref/templates/builtins>` for examples of this. |
|
415 |
|
416 * The :djadmin:`dumpdata` management command now accepts individual |
|
417 model names as arguments, allowing you to export the data just from |
|
418 particular models. |
|
419 |
|
420 * There's a new :tfilter:`safeseq` template filter which works just like |
|
421 :tfilter:`safe` for lists, marking each item in the list as safe. |
|
422 |
|
423 * :doc:`Cache backends </topics/cache>` now support ``incr()`` and |
|
424 ``decr()`` commands to increment and decrement the value of a cache key. |
|
425 On cache backends that support atomic increment/decrement -- most |
|
426 notably, the memcached backend -- these operations will be atomic, and |
|
427 quite fast. |
|
428 |
|
429 * Django now can :doc:`easily delegate authentication to the Web server |
|
430 </howto/auth-remote-user>` via a new authentication backend that supports |
|
431 the standard ``REMOTE_USER`` environment variable used for this purpose. |
|
432 |
|
433 * There's a new :func:`django.shortcuts.redirect` function that makes it |
|
434 easier to issue redirects given an object, a view name, or a URL. |
|
435 |
|
436 * The ``postgresql_psycopg2`` backend now supports :ref:`native PostgreSQL |
|
437 autocommit <postgresql-notes>`. This is an advanced, PostgreSQL-specific |
|
438 feature, that can make certain read-heavy applications a good deal |
|
439 faster. |
|
440 |
|
441 What's next? |
|
442 ============ |
|
443 |
|
444 We'll take a short break, and then work on Django 1.2 will begin -- no rest for |
|
445 the weary! If you'd like to help, discussion of Django development, including |
|
446 progress toward the 1.2 release, takes place daily on the django-developers |
|
447 mailing list: |
|
448 |
|
449 * http://groups.google.com/group/django-developers |
|
450 |
|
451 ... and in the ``#django-dev`` IRC channel on ``irc.freenode.net``. Feel free to |
|
452 join the discussions! |
|
453 |
|
454 Django's online documentation also includes pointers on how to contribute to |
|
455 Django: |
|
456 |
|
457 * :doc:`How to contribute to Django </internals/contributing>` |
|
458 |
|
459 Contributions on any level -- developing code, writing documentation or simply |
|
460 triaging tickets and helping to test proposed bugfixes -- are always welcome and |
|
461 appreciated. |
|
462 |
|
463 And that's the way it is. |