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