1.7.txt 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315
  1. ============================================
  2. Django 1.7 release notes - UNDER DEVELOPMENT
  3. ============================================
  4. Welcome to Django 1.7!
  5. These release notes cover the `new features`_, as well as some `backwards
  6. incompatible changes`_ you'll want to be aware of when upgrading from Django
  7. 1.6 or older versions. We've also dropped some features, which are detailed in
  8. :ref:`our deprecation plan <deprecation-removed-in-1.7>`, and we've `begun the
  9. deprecation process for some features`_.
  10. .. _`new features`: `What's new in Django 1.7`_
  11. .. _`backwards incompatible changes`: `Backwards incompatible changes in 1.7`_
  12. .. _`begun the deprecation process for some features`: `Features deprecated in 1.7`_
  13. Python compatibility
  14. ====================
  15. Django 1.7 requires Python 2.7 or above, though we **highly recommend**
  16. the latest minor release. Support for Python 2.6 has been dropped.
  17. This change should affect only a small number of Django users, as most
  18. operating-system vendors today are shipping Python 2.7 or newer as their default
  19. version. If you're still using Python 2.6, however, you'll need to stick to
  20. Django 1.6 until you can upgrade your Python version. Per :doc:`our support
  21. policy </internals/release-process>`, Django 1.6 will continue to receive
  22. security support until the release of Django 1.8.
  23. What's new in Django 1.7
  24. ========================
  25. Schema migrations
  26. ~~~~~~~~~~~~~~~~~
  27. Django now has built-in support for schema migrations. It allows models
  28. to be updated, changed, and deleted by creating migration files that represent
  29. the model changes and which can be run on any development, staging or production
  30. database.
  31. Migrations are covered in :doc:`their own documentation</topics/migrations>`,
  32. but a few of the key features are:
  33. * ``syncdb`` has been deprecated and replaced by ``migrate``. Don't worry -
  34. calls to ``syncdb`` will still work as before.
  35. * A new ``makemigrations`` command provides an easy way to autodetect changes
  36. to your models and make migrations for them.
  37. :data:`~django.db.models.signals.pre_syncdb` and
  38. :data:`~django.db.models.signals.post_syncdb` have been replaced by
  39. :data:`~django.db.models.signals.pre_migrate` and
  40. :data:`~django.db.models.signals.post_migrate` respectively. These new
  41. signals have slightly different arguments. Check the documentation for
  42. details.
  43. * The ``allow_syncdb`` method on database routers is now called ``allow_migrate``,
  44. but still performs the same function. Routers with ``allow_syncdb`` methods
  45. will still work, but that method name is deprecated and you should change
  46. it as soon as possible (nothing more than renaming is required).
  47. * ``initial_data`` fixtures are no longer loaded for apps with migrations; if
  48. you want to load initial data for an app, we suggest you do it in a migration.
  49. App-loading refactor
  50. ~~~~~~~~~~~~~~~~~~~~
  51. Historically, Django applications were tightly linked to models. A singleton
  52. known as the "app cache" dealt with both installed applications and models.
  53. The models module was used as an identifier for applications in many APIs.
  54. As the concept of :doc:`Django applications </ref/applications>` matured, this
  55. code showed some shortcomings. It has been refactored into an "app registry"
  56. where models modules no longer have a central role and where it's possible to
  57. attach configuration data to applications.
  58. Improvements thus far include:
  59. * Applications can run code at startup, before Django does anything else, with
  60. the :meth:`~django.apps.AppConfig.ready` method of their configuration.
  61. * Application labels are assigned correctly to models even when they're
  62. defined outside of ``models.py``. You don't have to set
  63. :attr:`~django.db.models.Options.app_label` explicitly any more.
  64. * It is possible to omit ``models.py`` entirely if an application doesn't
  65. have any models.
  66. * Applications can be relabeled with the :attr:`~django.apps.AppConfig.label`
  67. attribute of application configurations, to work around label conflicts.
  68. * The name of applications can be customized in the admin with the
  69. :attr:`~django.apps.AppConfig.verbose_name` of application configurations.
  70. * The admin automatically calls :func:`~django.contrib.admin.autodiscover()`
  71. when Django starts. You can consequently remove this line from your
  72. URLconf.
  73. * Django imports all application configurations and models as soon as it
  74. starts, through a deterministic and straightforward process. This should
  75. make it easier to diagnose import issues such as import loops.
  76. New method on Field subclasses
  77. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  78. To help power both schema migrations and composite keys, the :class:`~django.db.models.Field` API now
  79. has a new required method: ``deconstruct()``.
  80. This method takes no arguments, and returns a tuple of four items:
  81. * ``name``: The field's attribute name on its parent model, or None if it is not part of a model
  82. * ``path``: A dotted, Python path to the class of this field, including the class name.
  83. * ``args``: Positional arguments, as a list
  84. * ``kwargs``: Keyword arguments, as a dict
  85. These four values allow any field to be serialized into a file, as well as
  86. allowing the field to be copied safely, both essential parts of these new features.
  87. This change should not affect you unless you write custom Field subclasses;
  88. if you do, you may need to reimplement the ``deconstruct()`` method if your
  89. subclass changes the method signature of ``__init__`` in any way. If your
  90. field just inherits from a built-in Django field and doesn't override ``__init__``,
  91. no changes are necessary.
  92. If you do need to override ``deconstruct()``, a good place to start is the
  93. built-in Django fields (``django/db/models/fields/__init__.py``) as several
  94. fields, including ``DecimalField`` and ``DateField``, override it and show how
  95. to call the method on the superclass and simply add or remove extra arguments.
  96. Calling custom ``QuerySet`` methods from the ``Manager``
  97. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  98. Historically, the recommended way to make reusable model queries was to create
  99. methods on a custom ``Manager`` class. The problem with this approach was that
  100. after the first method call, you'd get back a ``QuerySet`` instance and
  101. couldn't call additional custom manager methods.
  102. Though not documented, it was common to work around this issue by creating a
  103. custom ``QuerySet`` so that custom methods could be chained; but the solution
  104. had a number of drawbacks:
  105. * The custom ``QuerySet`` and its custom methods were lost after the first
  106. call to ``values()`` or ``values_list()``.
  107. * Writing a custom ``Manager`` was still necessary to return the custom
  108. ``QuerySet`` class and all methods that were desired on the ``Manager``
  109. had to be proxied to the ``QuerySet``. The whole process went against
  110. the DRY principle.
  111. The :meth:`QuerySet.as_manager() <django.db.models.query.QuerySet.as_manager>`
  112. class method can now directly :ref:`create Manager with QuerySet methods
  113. <create-manager-with-queryset-methods>`::
  114. class FoodQuerySet(models.QuerySet):
  115. def pizzas(self):
  116. return self.filter(kind='pizza')
  117. def vegetarian(self):
  118. return self.filter(vegetarian=True)
  119. class Food(models.Model):
  120. kind = models.CharField(max_length=50)
  121. vegetarian = models.BooleanField()
  122. objects = FoodQuerySet.as_manager()
  123. Food.objects.pizzas().vegetarian()
  124. Using a custom manager when traversing reverse relations
  125. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  126. It is now possible to :ref:`specify a custom manager
  127. <using-custom-reverse-manager>` when traversing a reverse relationship.
  128. New system check framework
  129. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  130. We've added a new :doc:`System check framework </ref/checks>` for
  131. detecting common problems (like invalid models) and providing hints for
  132. resolving those problems. The framework is extensible so you can add your
  133. own checks for your own apps and libraries.
  134. To perform system checks, you use the :djadmin:`check` management command.
  135. This command replaces the older :djadmin:`validate` management command.
  136. New ``Prefetch`` object for advanced ``prefetch_related`` operations.
  137. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  138. The new :class:`~django.db.models.Prefetch` object allows customizing
  139. prefetch operations.
  140. You can specify the ``QuerySet`` used to traverse a given relation
  141. or customize the storage location of prefetch results.
  142. This enables things like filtering prefetched relations, calling
  143. :meth:`~django.db.models.query.QuerySet.select_related()` from a prefetched
  144. relation, or prefetching the same relation multiple times with different
  145. querysets. See :meth:`~django.db.models.query.QuerySet.prefetch_related()`
  146. for more details.
  147. Admin shortcuts support time zones
  148. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  149. The "today" and "now" shortcuts next to date and time input widgets in the
  150. admin are now operating in the :ref:`current time zone
  151. <default-current-time-zone>`. Previously, they used the browser time zone,
  152. which could result in saving the wrong value when it didn't match the current
  153. time zone on the server.
  154. In addition, the widgets now display a help message when the browser and
  155. server time zone are different, to clarify how the value inserted in the field
  156. will be interpreted.
  157. Using database cursors as context managers
  158. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  159. Prior to Python 2.7, database cursors could be used as a context manager. The
  160. specific backend's cursor defined the behavior of the context manager. The
  161. behavior of magic method lookups was changed with Python 2.7 and cursors were
  162. no longer usable as context managers.
  163. Django 1.7 allows a cursor to be used as a context manager that is a shortcut
  164. for the following, instead of backend specific behavior.
  165. .. code-block:: python
  166. c = connection.cursor()
  167. try:
  168. c.execute(...)
  169. finally:
  170. c.close()
  171. Custom lookups
  172. ~~~~~~~~~~~~~~
  173. It is now possible to write custom lookups and transforms for the ORM.
  174. Custom lookups work just like Django's inbuilt lookups (e.g. ``lte``,
  175. ``icontains``) while transforms are a new concept.
  176. The :class:`django.db.models.Lookup` class provides a way to add lookup
  177. operators for model fields. As an example it is possible to add ``day_lte``
  178. operator for ``DateFields``.
  179. The :class:`django.db.models.Transform` class allows transformations of
  180. database values prior to the final lookup. For example it is possible to
  181. write a ``year`` transform that extracts year from the field's value.
  182. Transforms allow for chaining. After the ``year`` transform has been added
  183. to ``DateField`` it is possible to filter on the transformed value, for
  184. example ``qs.filter(author__birthdate__year__lte=1981)``.
  185. For more information about both custom lookups and transforms refer to
  186. :doc:`custom lookups </ref/models/custom-lookups>` documentation.
  187. Minor features
  188. ~~~~~~~~~~~~~~
  189. :mod:`django.contrib.admin`
  190. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  191. * You can now implement :attr:`~django.contrib.admin.AdminSite.site_header`,
  192. :attr:`~django.contrib.admin.AdminSite.site_title`, and
  193. :attr:`~django.contrib.admin.AdminSite.index_title` attributes on a custom
  194. :class:`~django.contrib.admin.AdminSite` in order to easily change the admin
  195. site's page title and header text. No more needing to override templates!
  196. * Buttons in :mod:`django.contrib.admin` now use the ``border-radius`` CSS
  197. property for rounded corners rather than GIF background images.
  198. * Some admin templates now have ``app-<app_name>`` and ``model-<model_name>``
  199. classes in their ``<body>`` tag to allow customizing the CSS per app or per
  200. model.
  201. * The admin changelist cells now have a ``field-<field_name>`` class in the
  202. HTML to enable style customizations.
  203. * The admin's search fields can now be customized per-request thanks to the new
  204. :meth:`django.contrib.admin.ModelAdmin.get_search_fields` method.
  205. * The :meth:`ModelAdmin.get_fields()
  206. <django.contrib.admin.ModelAdmin.get_fields>` method may be overridden to
  207. customize the value of :attr:`ModelAdmin.fields
  208. <django.contrib.admin.ModelAdmin.fields>`.
  209. * In addition to the existing ``admin.site.register`` syntax, you can use the
  210. new :func:`~django.contrib.admin.register` decorator to register a
  211. :class:`~django.contrib.admin.ModelAdmin`.
  212. * You may specify :meth:`ModelAdmin.list_display_links
  213. <django.contrib.admin.ModelAdmin.list_display_links>` ``= None`` to disable
  214. links on the change list page grid.
  215. * You may now specify :attr:`ModelAdmin.view_on_site
  216. <django.contrib.admin.ModelAdmin.view_on_site>` to control whether or not to
  217. display the "View on site" link.
  218. :mod:`django.contrib.auth`
  219. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  220. * Any ``**kwargs`` passed to
  221. :meth:`~django.contrib.auth.models.User.email_user()` are passed to the
  222. underlying :meth:`~django.core.mail.send_mail()` call.
  223. * The :func:`~django.contrib.auth.decorators.permission_required` decorator can
  224. take a list of permissions as well as a single permission.
  225. * You can override the new :meth:`AuthenticationForm.confirm_login_allowed()
  226. <django.contrib.auth.forms.AuthenticationForm.confirm_login_allowed>` method
  227. to more easily customize the login policy.
  228. * :func:`django.contrib.auth.views.password_reset` takes an optional
  229. ``html_email_template_name`` parameter used to send a multipart HTML email
  230. for password resets.
  231. :mod:`django.contrib.formtools`
  232. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  233. * Calls to :meth:`WizardView.done()
  234. <django.contrib.formtools.wizard.views.WizardView.done>` now include a
  235. ``form_dict`` to allow easier access to forms by their step name.
  236. :mod:`django.contrib.gis`
  237. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  238. * The default OpenLayers library version included in widgets has been updated
  239. from 2.11 to 2.13.
  240. * Prepared geometries now also support the ``crosses``, ``disjoint``,
  241. ``overlaps``, ``touches`` and ``within`` predicates, if GEOS 3.3 or later is
  242. installed.
  243. :mod:`django.contrib.messages`
  244. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  245. * The backends for :mod:`django.contrib.messages` that use cookies, will now
  246. follow the :setting:`SESSION_COOKIE_SECURE` and
  247. :setting:`SESSION_COOKIE_HTTPONLY` settings.
  248. * The :ref:`messages context processor <message-displaying>` now adds a
  249. dictionary of default levels under the name ``DEFAULT_MESSAGE_LEVELS``.
  250. * :class:`~django.contrib.messages.storage.base.Message` objects now have a
  251. ``level_tag`` attribute that contains the string representation of the
  252. message level.
  253. :mod:`django.contrib.redirects`
  254. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  255. * :class:`~django.contrib.redirects.middleware.RedirectFallbackMiddleware`
  256. has two new attributes
  257. (:attr:`~django.contrib.redirects.middleware.RedirectFallbackMiddleware.response_gone_class`
  258. and
  259. :attr:`~django.contrib.redirects.middleware.RedirectFallbackMiddleware.response_redirect_class`)
  260. that specify the types of :class:`~django.http.HttpResponse` instances the
  261. middleware returns.
  262. :mod:`django.contrib.sessions`
  263. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  264. * The ``"django.contrib.sessions.backends.cached_db"`` session backend now
  265. respects :setting:`SESSION_CACHE_ALIAS`. In previous versions, it always used
  266. the `default` cache.
  267. :mod:`django.contrib.sitemaps`
  268. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  269. * The :mod:`sitemap framework<django.contrib.sitemaps>` now makes use of
  270. :attr:`~django.contrib.sitemaps.Sitemap.lastmod` to set a ``Last-Modified``
  271. header in the response. This makes it possible for the
  272. :class:`~django.middleware.http.ConditionalGetMiddleware` to handle
  273. conditional ``GET`` requests for sitemaps which set ``lastmod``.
  274. :mod:`django.contrib.sites`
  275. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  276. * The new :class:`django.contrib.site.middleware.CurrentSiteMiddleware` allows
  277. setting the current site on each request.
  278. :mod:`django.contrib.staticfiles`
  279. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  280. * The :ref:`static files storage classes <staticfiles-storages>` may be
  281. subclassed to override the permissions that collected static files and
  282. directories receive by setting the
  283. :attr:`~django.core.files.storage.FileSystemStorage.file_permissions_mode`
  284. and :attr:`~django.core.files.storage.FileSystemStorage.directory_permissions_mode`
  285. parameters. See :djadmin:`collectstatic` for example usage.
  286. * The :class:`~django.contrib.staticfiles.storage.CachedStaticFilesStorage`
  287. backend gets a sibling class called
  288. :class:`~django.contrib.staticfiles.storage.ManifestStaticFilesStorage`
  289. that doesn't use the cache system at all but instead a JSON file called
  290. ``staticfiles.json`` for storing the mapping between the original file name
  291. (e.g. ``css/styles.css``) and the hashed file name (e.g.
  292. ``css/styles.55e7cbb9ba48.css``. The ``staticfiles.json`` file is created
  293. when running the :djadmin:`collectstatic` management command and should
  294. be a less expensive alternative for remote storages such as Amazon S3.
  295. See the :class:`~django.contrib.staticfiles.storage.ManifestStaticFilesStorage`
  296. docs for more information.
  297. * :djadmin:`findstatic` now accepts verbosity flag level 2, meaning it will
  298. show the relative paths of the directories it searched. See
  299. :djadmin:`findstatic` for example output.
  300. :mod:`django.contrib.syndication`
  301. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  302. * The :class:`~django.utils.feedgenerator.Atom1Feed` syndication feed's
  303. ``updated`` element now utilizes ``updateddate`` instead of ``pubdate``,
  304. allowing the ``published`` element to be included in the feed (which
  305. relies on ``pubdate``).
  306. Cache
  307. ^^^^^
  308. * Access to caches configured in :setting:`CACHES` is now available via
  309. :data:`django.core.cache.caches`. This dict-like object provides a different
  310. instance per thread. It supersedes :func:`django.core.cache.get_cache` which
  311. is now deprecated.
  312. * If you instanciate cache backends directly, be aware that they aren't
  313. thread-safe any more, as :data:`django.core.cache.caches` now yields
  314. different instances per thread.
  315. Email
  316. ^^^^^
  317. * :func:`~django.core.mail.send_mail` now accepts an ``html_message``
  318. parameter for sending a multipart ``text/plain`` and ``text/html`` email.
  319. * The SMTP :class:`~django.core.mail.backends.smtp.EmailBackend` now accepts a
  320. :attr:`~django.core.mail.backends.smtp.EmailBackend.timeout` parameter.
  321. File Storage
  322. ^^^^^^^^^^^^
  323. * File locking on Windows previously depended on the PyWin32 package; if it
  324. wasn't installed, file locking failed silently. That dependency has been
  325. removed, and file locking is now implemented natively on both Windows
  326. and Unix.
  327. File Uploads
  328. ^^^^^^^^^^^^
  329. * The new :attr:`UploadedFile.content_type_extra
  330. <django.core.files.uploadedfile.UploadedFile.content_type_extra>` attribute
  331. contains extra parameters passed to the ``content-type`` header on a file
  332. upload.
  333. * The new :setting:`FILE_UPLOAD_DIRECTORY_PERMISSIONS` setting controls
  334. the file system permissions of directories created during file upload, like
  335. :setting:`FILE_UPLOAD_PERMISSIONS` does for the files themselves.
  336. * The :attr:`FileField.upload_to <django.db.models.FileField.upload_to>`
  337. attribute is now optional. If it is omitted or given ``None`` or an empty
  338. string, a subdirectory won't be used for storing the uploaded files.
  339. Forms
  340. ^^^^^
  341. * The ``<label>`` and ``<input>`` tags rendered by
  342. :class:`~django.forms.RadioSelect` and
  343. :class:`~django.forms.CheckboxSelectMultiple` when looping over the radio
  344. buttons or checkboxes now include ``for`` and ``id`` attributes, respectively.
  345. Each radio button or checkbox includes an ``id_for_label`` attribute to
  346. output the element's ID.
  347. * :attr:`Field.choices<django.db.models.Field.choices>` now allows you to
  348. customize the "empty choice" label by including a tuple with an empty string
  349. or ``None`` for the key and the custom label as the value. The default blank
  350. option ``"----------"`` will be omitted in this case.
  351. * :class:`~django.forms.MultiValueField` allows optional subfields by setting
  352. the ``require_all_fields`` argument to ``False``. The ``required`` attribute
  353. for each individual field will be respected, and a new ``incomplete``
  354. validation error will be raised when any required fields are empty.
  355. * The :meth:`~django.forms.Form.clean` method on a form no longer needs to
  356. return ``self.cleaned_data``. If it does return a changed dictionary then
  357. that will still be used.
  358. * After a temporary regression in Django 1.6, it's now possible again to make
  359. :class:`~django.forms.TypedChoiceField` ``coerce`` method return an arbitrary
  360. value.
  361. * :attr:`SelectDateWidget.months
  362. <django.forms.extras.widgets.SelectDateWidget.months>` can be used to
  363. customize the wording of the months displayed in the select widget.
  364. * The ``min_num`` and ``validate_min`` parameters were added to
  365. :func:`~django.forms.formsets.formset_factory` to allow validating
  366. a minimum number of submitted forms.
  367. * The metaclasses used by ``Form`` and ``ModelForm`` have been reworked to
  368. support more inheritance scenarios. The previous limitation that prevented
  369. inheriting from both ``Form`` and ``ModelForm`` simultaneously have been
  370. removed as long as ``ModelForm`` appears first in the MRO.
  371. * It's now possible to opt-out from a ``Form`` field declared in a parent class
  372. by shadowing it with a non-``Field`` value.
  373. * The new :meth:`~django.forms.Form.add_error()` method allows adding errors
  374. to specific form fields.
  375. * The dict-like attribute :attr:`~django.forms.Form.errors` now has two new
  376. methods :meth:`~django.forms.Form.errors.as_data()` and
  377. :meth:`~django.forms.Form.errors.as_json()`. The former returns a ``dict``
  378. that maps fields to their original errors, complete with all metadata
  379. (error code and params), the latter returns the errors serialized as json.
  380. * It's now possible to customize the error messages for ``ModelForm``’s
  381. ``unique``, ``unique_for_date``, and ``unique_together`` constraints.
  382. In order to support ``unique_together`` or any other ``NON_FIELD_ERROR``,
  383. ``ModelForm`` now looks for the ``NON_FIELD_ERROR`` key in the
  384. ``error_messages`` dictionary of the ``ModelForm``’s inner ``Meta`` class.
  385. See :ref:`considerations regarding model's error_messages
  386. <considerations-regarding-model-errormessages>` for more details.
  387. Internationalization
  388. ^^^^^^^^^^^^^^^^^^^^
  389. * The :attr:`django.middleware.locale.LocaleMiddleware.response_redirect_class`
  390. attribute allows you to customize the redirects issued by the middleware.
  391. * The :class:`~django.middleware.locale.LocaleMiddleware` now stores the user's
  392. selected language with the session key ``_language``. Previously it was
  393. stored with the key ``django_language``, but keys reserved for Django should
  394. start with an underscore. For backwards compatibility ``django_language`` is
  395. still read from in 1.7. Sessions will be migrated to the new ``_language``
  396. key as they are written.
  397. * The :ttag:`blocktrans` now supports a ``trimmed`` option. This
  398. option will remove newline characters from the beginning and the end of the
  399. content of the ``{% blocktrans %}`` tag, replace any whitespace at the
  400. beginning and end of a line and merge all lines into one using a space
  401. character to separate them. This is quite useful for indenting the content of
  402. a ``{% blocktrans %}`` tag without having the indentation characters end up
  403. in the corresponding entry in the PO file, which makes the translation
  404. process easier.
  405. * When you run :djadmin:`makemessages` from the root directory of your project,
  406. any extracted strings will now be automatically distributed to the proper
  407. app or project message file. See :ref:`how-to-create-language-files` for
  408. details.
  409. Management Commands
  410. ^^^^^^^^^^^^^^^^^^^
  411. * The :djadminopt:`--no-color` option for ``django-admin.py`` allows you to
  412. disable the colorization of management command output.
  413. * The new :djadminopt:`--natural-foreign` and :djadminopt:`--natural-primary`
  414. options for :djadmin:`dumpdata`, and the new ``use_natural_foreign_keys`` and
  415. ``use_natural_primary_keys`` arguments for ``serializers.serialize()``, allow
  416. the use of natural primary keys when serializing.
  417. * It is no longer necessary to provide the cache table name or the
  418. :djadminopt:`--database` option for the :djadmin:`createcachetable` command.
  419. Django takes this information from your settings file. If you have configured
  420. multiple caches or multiple databases, all cache tables are created.
  421. * The :djadmin:`runserver` command received several improvements:
  422. * On Linux systems, if pyinotify_ is installed, the development server will
  423. reload immediately when a file is changed. Previously, it polled the
  424. filesystem for changes every second. That caused a small delay before
  425. reloads and reduced battery life on laptops.
  426. .. _pyinotify: https://pypi.python.org/pypi/pyinotify
  427. * In addition, the development server automatically reloads when a
  428. translation file is updated, i.e. after running
  429. :djadmin:`compilemessages`.
  430. * All HTTP requests are logged to the console, including requests for static
  431. files or ``favicon.ico`` that used to be filtered out.
  432. * Management commands can now produce syntax colored output under Windows if
  433. the ANSICON third-party tool is installed and active.
  434. * :djadmin:`collectstatic` command with symlink option is now supported on
  435. Windows NT 6 (Windows Vista and newer).
  436. Models
  437. ^^^^^^
  438. * The :meth:`QuerySet.update_or_create()
  439. <django.db.models.query.QuerySet.update_or_create>` method was added.
  440. * The new :attr:`~django.db.models.Options.default_permissions` model
  441. ``Meta`` option allows you to customize (or disable) creation of the default
  442. add, change, and delete permissions.
  443. * Explicit :class:`~django.db.models.OneToOneField` for
  444. :ref:`multi-table-inheritance` are now discovered in abstract classes.
  445. * Is it now possible to avoid creating a backward relation for
  446. :class:`~django.db.models.OneToOneField` by setting its
  447. :attr:`~django.db.models.ForeignKey.related_name` to
  448. ``'+'`` or ending it with ``'+'``.
  449. * :class:`F expressions <django.db.models.F>` support the power operator
  450. (``**``).
  451. * The ``remove()`` and ``clear()`` methods of the related managers created by
  452. ``ForeignKey`` and ``GenericForeignKey`` now accept the ``bulk`` keyword
  453. argument to control whether or not to perform operations in bulk
  454. (i.e. using ``QuerySet.update()``). Defaults to ``True``.
  455. * It is now possible to use ``None`` as a query value for the :lookup:`iexact`
  456. lookup.
  457. Signals
  458. ^^^^^^^
  459. * The ``enter`` argument was added to the
  460. :data:`~django.test.signals.setting_changed` signal.
  461. * The model signals can be now be connected to using a ``str`` of the
  462. ``'app_label.ModelName'`` form – just like related fields – to lazily
  463. reference their senders.
  464. Templates
  465. ^^^^^^^^^
  466. * The :meth:`Context.push() <django.template.Context.push>` method now returns
  467. a context manager which automatically calls :meth:`pop()
  468. <django.template.Context.pop>` upon exiting the ``with`` statement.
  469. Additionally, :meth:`push() <django.template.Context.push>` now accepts
  470. parameters that are passed to the ``dict`` constructor used to build the new
  471. context level.
  472. * The :ttag:`widthratio` template tag now accepts an "as" parameter to capture
  473. the result in a variable.
  474. * The :ttag:`include` template tag will now also accept anything with a
  475. ``render()`` method (such as a ``Template``) as an argument. String
  476. arguments will be looked up using
  477. :func:`~django.template.loader.get_template` as always.
  478. * It is now possible to :ttag:`include` templates recursively.
  479. * Template objects now have an origin attribute set when
  480. :setting:`TEMPLATE_DEBUG` is ``True``. This allows template origins to be
  481. inspected and logged outside of the ``django.template`` infrastructure.
  482. * ``TypeError`` exceptions are no longer silenced when raised during the
  483. rendering of a template.
  484. * The following functions now accept a ``dirs`` parameter which is a list or
  485. tuple to override :setting:`TEMPLATE_DIRS`:
  486. * :func:`django.template.loader.get_template()`
  487. * :func:`django.template.loader.select_template()`
  488. * :func:`django.shortcuts.render()`
  489. * :func:`django.shortcuts.render_to_response()`
  490. * The :tfilter:`time` filter now accepts timzone-related :ref:`format
  491. specifiers <date-and-time-formatting-specifiers>` ``'e'``, ``'O'`` , ``'T'``
  492. and ``'Z'`` and is able to digest :ref:`time-zone-aware
  493. <naive_vs_aware_datetimes>` ``datetime`` instances performing the expected
  494. rendering.
  495. * The :ttag:`cache` tag will now try to use the cache called
  496. "template_fragments" if it exists and fall back to using the default cache
  497. otherwise. It also now accepts an optional ``using`` keyword argument to
  498. control which cache it uses.
  499. Requests
  500. ^^^^^^^^
  501. * The new :attr:`HttpRequest.scheme <django.http.HttpRequest.scheme>` attribute
  502. specifies the scheme of the request (``http`` or ``https`` normally).
  503. Tests
  504. ^^^^^
  505. * :class:`~django.test.runner.DiscoverRunner` has two new attributes,
  506. :attr:`~django.test.runner.DiscoverRunner.test_suite` and
  507. :attr:`~django.test.runner.DiscoverRunner.test_runner`, which facilitate
  508. overriding the way tests are collected and run.
  509. * The ``fetch_redirect_response`` argument was added to
  510. :meth:`~django.test.SimpleTestCase.assertRedirects`. Since the test
  511. client can't fetch externals URLs, this allows you to use ``assertRedirects``
  512. with redirects that aren't part of your Django app.
  513. * Correct handling of scheme when making comparisons in
  514. :meth:`~django.test.SimpleTestCase.assertRedirects`.
  515. * The ``secure`` argument was added to all the request methods of
  516. :class:`~django.test.Client`. If ``True``, the request will be made
  517. through HTTPS.
  518. * Requests made with :meth:`Client.login() <django.test.Client.login>` and
  519. :meth:`Client.logout() <django.test.Client.logout>` respect defaults defined
  520. in :class:`~django.test.Client` instantiation and are processed through
  521. middleware.
  522. * :meth:`~django.test.TransactionTestCase.assertNumQueries` now prints
  523. out the list of executed queries if the assertion fails.
  524. * The ``WSGIRequest`` instance generated by the test handler is now attached to
  525. the :attr:`django.test.Response.wsgi_request` attribute.
  526. Validators
  527. ^^^^^^^^^^
  528. * :class:`~django.core.validators.RegexValidator` now accepts an optional
  529. Boolean :attr:`~django.core.validators.RegexValidator.inverse_match` argument
  530. which determines if the :exc:`~django.core.exceptions.ValidationError` should
  531. be raised when the regular expression pattern matches (``True``) or does not
  532. match (``False``, by default) the provided ``value``.
  533. * :class:`~django.core.validators.URLValidator` now accepts an optional
  534. ``schemes`` argument which allows customization of the accepted URI schemes
  535. (instead of the defaults ``http(s)`` and ``ftp(s)``).
  536. Backwards incompatible changes in 1.7
  537. =====================================
  538. .. warning::
  539. In addition to the changes outlined in this section, be sure to review the
  540. :doc:`deprecation plan </internals/deprecation>` for any features that
  541. have been removed. If you haven't updated your code within the
  542. deprecation timeline for a given feature, its removal may appear as a
  543. backwards incompatible change.
  544. allow_syncdb/allow_migrate
  545. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  546. While Django will still look at ``allow_syncdb`` methods even though they
  547. should be renamed to ``allow_migrate``, there is a subtle difference in which
  548. models get passed to these methods.
  549. For apps with migrations, ``allow_migrate`` will now get passed
  550. :ref:`historical models <historical-models>`, which are special versioned models
  551. without custom attributes, methods or managers. Make sure your ``allow_migrate``
  552. methods are only referring to fields or other items in ``model._meta``.
  553. initial_data
  554. ~~~~~~~~~~~~
  555. Apps with migrations will not load ``initial_data`` fixtures when they have
  556. finished migrating. Apps without migrations will continue to load these fixtures
  557. during the phase of ``migrate`` which emulates the old ``syncdb`` behaviour,
  558. but any new apps will not have this support.
  559. Instead, you are encouraged to load initial data in migrations if you need it
  560. (using the ``RunPython`` operation and your model classes);
  561. this has the added advantage that your initial data will not need updating
  562. every time you change the schema.
  563. App-loading changes
  564. ~~~~~~~~~~~~~~~~~~~
  565. Start-up sequence
  566. ^^^^^^^^^^^^^^^^^
  567. Django 1.7 loads application configurations and models as soon as it starts.
  568. While this behavior is more straightforward and is believed to be more robust,
  569. regressions cannot be ruled out. You may encounter the following exceptions:
  570. * ``RuntimeError: App registry isn't ready yet.`` This happens when importing
  571. an application configuration or a models module triggers code that depends
  572. on the app registry.
  573. For example, :func:`~django.utils.translation.ugettext()` uses the app
  574. registry to look up translation catalogs in applications. To translate at
  575. import time, you need :func:`~django.utils.translation.ugettext_lazy()`
  576. instead. (Using :func:`~django.utils.translation.ugettext()` would be a bug,
  577. because the translation would happen at import time, rather than at each
  578. request depending on the active language.)
  579. Executing database queries with the ORM at import time in models modules
  580. will also trigger this exception. The ORM cannot function properly until all
  581. models are available.
  582. * ``ImportError: cannot import name ...`` This happens if the import sequence
  583. ends up in a loop.
  584. To eliminate such problems, you should minimize dependencies between your
  585. models modules and do as little work as possible at import time. To avoid
  586. executing code at import time, you can move it into a function and cache its
  587. results. The code will be executed when you first need its results. This
  588. concept is known as "lazy evaluation".
  589. * ``django.contrib.admin`` will now automatically perform autodiscovery of
  590. ``admin`` modules in installed applications. To prevent it, change your
  591. :setting:`INSTALLED_APPS` to contain
  592. ``'django.contrib.admin.apps.SimpleAdminConfig'`` instead of
  593. ``'django.contrib.admin'``.
  594. Standalone scripts
  595. ^^^^^^^^^^^^^^^^^^
  596. If you're using Django in a plain Python script — rather than a management
  597. command — and you rely on the :envvar:`DJANGO_SETTINGS_MODULE` environment
  598. variable, you must now explicitly initialize Django at the beginning of your
  599. script with::
  600. >>> import django
  601. >>> django.setup()
  602. Otherwise, you will hit ``RuntimeError: App registry isn't ready yet.``
  603. App registry consistency
  604. ^^^^^^^^^^^^^^^^^^^^^^^^
  605. It is no longer possible to have multiple installed applications with the same
  606. label. In previous versions of Django, this didn't always work correctly, but
  607. didn't crash outright either.
  608. If you have two apps with the same label, you should create an
  609. :class:`~django.apps.AppConfig` for one of them and override its
  610. :class:`~django.apps.AppConfig.label` there. You should then adjust your code
  611. wherever it references this application or its models with the old label.
  612. It isn't possible to import the same model twice through different paths any
  613. more. As of Django 1.6, this may happen only if you're manually putting a
  614. directory and a subdirectory on :envvar:`PYTHONPATH`. Refer to the section on
  615. the new project layout in the :doc:`1.4 release notes </releases/1.4>` for
  616. migration instructions.
  617. You should make sure that:
  618. * All models are defined in applications that are listed in
  619. :setting:`INSTALLED_APPS` or have an explicit
  620. :attr:`~django.db.models.Options.app_label`.
  621. * Models aren't imported as a side-effect of loading their application.
  622. Specifically, you shouldn't import models in the root module of an
  623. application nor in the module that define its configuration class.
  624. Django will enforce these requirements as of version 1.9, after a deprecation
  625. period.
  626. Subclassing AppCommand
  627. ^^^^^^^^^^^^^^^^^^^^^^
  628. Subclasses of :class:`~django.core.management.AppCommand` must now implement a
  629. :meth:`~django.core.management.AppCommand.handle_app_config` method instead of
  630. ``handle_app()``. This method receives an :class:`~django.apps.AppConfig`
  631. instance instead of a models module.
  632. Introspecting applications
  633. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  634. Since :setting:`INSTALLED_APPS` now supports application configuration classes
  635. in addition to application modules, you should review code that accesses this
  636. setting directly and use the app registry (:attr:`django.apps.apps`) instead.
  637. The app registry has preserved some features of the old app cache. Even though
  638. the app cache was a private API, obsolete methods and arguments will be
  639. removed through a standard deprecation path, with the exception of the
  640. following changes that take effect immediately:
  641. * ``get_model`` raises :exc:`~exceptions.LookupError` instead of returning
  642. ``None`` when no model is found.
  643. * The ``only_installed`` argument of ``get_model`` and ``get_models`` no
  644. longer exists, nor does the ``seed_cache`` argument of ``get_model``.
  645. Management commands and order of :setting:`INSTALLED_APPS`
  646. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  647. When several applications provide management commands with the same name,
  648. Django loads the command from the application that comes first in
  649. :setting:`INSTALLED_APPS`. Previous versions loaded the command from the
  650. application that came last.
  651. This brings discovery of management commands in line with other parts of
  652. Django that rely on the order of :setting:`INSTALLED_APPS`, such as static
  653. files, templates, and translations.
  654. Behavior of ``LocMemCache`` regarding pickle errors
  655. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  656. An inconsistency existed in previous versions of Django regarding how pickle
  657. errors are handled by different cache backends.
  658. ``django.core.cache.backends.locmem.LocMemCache`` used to fail silently when
  659. such an error occurs, which is inconsistent with other backends and leads to
  660. cache-specific errors. This has been fixed in Django 1.7, see
  661. `Ticket #21200`_ for more details.
  662. .. _Ticket #21200: https://code.djangoproject.com/ticket/21200
  663. Cache keys are now generated from the request's absolute URL
  664. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  665. Previous versions of Django generated cache keys using a request's path and
  666. query string but not the scheme or host. If a Django application was serving
  667. multiple subdomains or domains, cache keys could collide. In Django 1.7, cache
  668. keys vary by the absolute URL of the request including scheme, host, path, and
  669. query string. For example, the URL portion of a cache key is now generated from
  670. ``http://www.example.com/path/to/?key=val`` rather than ``/path/to/?key=val``.
  671. The cache keys generated by Django 1.7 will be different from the keys
  672. generated by older versions of Django. After upgrading to Django 1.7, the first
  673. request to any previously cached URL will be a cache miss .
  674. Passing ``None`` to ``Manager.db_manager()``
  675. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  676. In previous versions of Django, it was possible to use
  677. ``db_manager(using=None)`` on a model manager instance to obtain a manager
  678. instance using default routing behavior, overriding any manually specified
  679. database routing. In Django 1.7, a value of ``None`` passed to db_manager will
  680. produce a router that *retains* any manually assigned database routing -- the
  681. manager will *not* be reset. This was necessary to resolve an inconsistency in
  682. the way routing information cascaded over joins. See `Ticket #13724`_ for more
  683. details.
  684. .. _Ticket #13724: https://code.djangoproject.com/ticket/13724
  685. pytz may be required
  686. ~~~~~~~~~~~~~~~~~~~~
  687. If your project handles datetimes before 1970 or after 2037 and Django raises
  688. a :exc:`~exceptions.ValueError` when encountering them, you will have to
  689. install pytz_. You may be affected by this problem if you use Django's time
  690. zone-related date formats or :mod:`django.contrib.syndication`.
  691. .. _pytz: https://pypi.python.org/pypi/pytz/
  692. ``remove()`` and ``clear()`` methods of related managers
  693. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  694. The ``remove()`` and ``clear()`` methods of the related managers created by
  695. ``ForeignKey``, ``GenericForeignKey``, and ``ManyToManyField`` suffered from a
  696. number of issues. Some operations ran multiple data modifying queries without
  697. wrapping them in a transaction, and some operations didn't respect default
  698. filtering when it was present (i.e. when the default manager on the related
  699. model implemented a custom ``get_queryset()``).
  700. Fixing the issues introduced some backward incompatible changes:
  701. - The default implementation of ``remove()`` for ``ForeignKey`` related managers
  702. changed from a series of ``Model.save()`` calls to a single
  703. ``QuerySet.update()`` call. The change means that ``pre_save`` and
  704. ``post_save`` signals aren't sent anymore. You can use the ``bulk=False``
  705. keyword argument to revert to the previous behavior.
  706. - The ``remove()`` and ``clear()`` methods for ``GenericForeignKey`` related
  707. managers now perform bulk delete. The ``Model.delete()`` method isn't called
  708. on each instance anymore. You can use the ``bulk=False`` keyword argument to
  709. revert to the previous behavior.
  710. - The ``remove()`` and ``clear()`` methods for ``ManyToManyField`` related
  711. managers perform nested queries when filtering is involved, which may or
  712. may not be an issue depending on your database and your data itself.
  713. See :ref:`this note <nested-queries-performance>` for more details.
  714. Admin login redirection strategy
  715. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  716. Historically, the Django admin site passed the request from an unauthorized or
  717. unauthenticated user directly to the login view, without HTTP redirection. In
  718. Django 1.7, this behavior changed to conform to a more traditional workflow
  719. where any unauthorized request to an admin page will be redirected (by HTTP
  720. status code 302) to the login page, with the ``next`` parameter set to the
  721. referring path. The user will be redirected there after a successful login.
  722. Note also that the admin login form has been updated to not contain the
  723. ``this_is_the_login_form`` field (now unused) and the ``ValidationError`` code
  724. has been set to the more regular ``invalid_login`` key.
  725. Miscellaneous
  726. ~~~~~~~~~~~~~
  727. * The :meth:`django.core.files.uploadhandler.FileUploadHandler.new_file()`
  728. method is now passed an additional ``content_type_extra`` parameter. If you
  729. have a custom :class:`~django.core.files.uploadhandler.FileUploadHandler`
  730. that implements ``new_file()``, be sure it accepts this new parameter.
  731. * :class:`ModelFormSet<django.forms.models.BaseModelFormSet>`\s no longer
  732. delete instances when ``save(commit=False)`` is called. See
  733. :attr:`~django.forms.formsets.BaseFormSet.can_delete` for instructions on how
  734. to manually delete objects from deleted forms.
  735. * Loading empty fixtures emits a ``RuntimeWarning`` rather than raising
  736. :class:`~django.core.management.CommandError`.
  737. * :func:`django.contrib.staticfiles.views.serve` will now raise an
  738. :exc:`~django.http.Http404` exception instead of
  739. :exc:`~django.core.exceptions.ImproperlyConfigured` when :setting:`DEBUG`
  740. is ``False``. This change removes the need to conditionally add the view to
  741. your root URLconf, which in turn makes it safe to reverse by name. It also
  742. removes the ability for visitors to generate spurious HTTP 500 errors by
  743. requesting static files that don't exist or haven't been collected yet.
  744. * The :meth:`django.db.models.Model.__eq__` method is now defined in a
  745. way where instances of a proxy model and its base model are considered
  746. equal when primary keys match. Previously only instances of exact same
  747. class were considered equal on primary key match.
  748. * The :meth:`django.db.models.Model.__eq__` method has changed such that
  749. two ``Model`` instances without primary key values won't be considered
  750. equal (unless they are the same instance).
  751. * The :meth:`django.db.models.Model.__hash__` will now raise ``TypeError``
  752. when called on an instance without a primary key value. This is done to
  753. avoid mutable ``__hash__`` values in containers.
  754. * :class:`~django.db.models.AutoField` columns in SQLite databases will now be
  755. created using the ``AUTOINCREMENT`` option, which guarantees monotonic
  756. increments. This will cause primary key numbering behavior to change on
  757. SQLite, becoming consistent with most other SQL databases. This will only
  758. apply to newly created tables. If you have a database created with an older
  759. version of Django, you will need to migrate it to take advantage of this
  760. feature. For example, you could do the following:
  761. #) Use :djadmin:`dumpdata` to save your data.
  762. #) Rename the existing database file (keep it as a backup).
  763. #) Run :djadmin:`migrate` to create the updated schema.
  764. #) Use :djadmin:`loaddata` to import the fixtures you exported in (1).
  765. * ``django.contrib.auth.models.AbstractUser`` no longer defines a
  766. :meth:`~django.db.models.Model.get_absolute_url()` method. The old definition
  767. returned ``"/users/%s/" % urlquote(self.username)`` which was arbitrary
  768. since applications may or may not define such a url in ``urlpatterns``.
  769. Define a ``get_absolute_url()`` method on your own custom user object or use
  770. :setting:`ABSOLUTE_URL_OVERRIDES` if you want a URL for your user.
  771. * The static asset-serving functionality of the
  772. :class:`django.test.LiveServerTestCase` class has been simplified: Now it's
  773. only able to serve content already present in :setting:`STATIC_ROOT` when
  774. tests are run. The ability to transparently serve all the static assets
  775. (similarly to what one gets with :setting:`DEBUG = True <DEBUG>` at
  776. development-time) has been moved to a new class that lives in the
  777. ``staticfiles`` application (the one actually in charge of such feature):
  778. :class:`django.contrib.staticfiles.testing.StaticLiveServerCase`. In other
  779. words, ``LiveServerTestCase`` itself is less powerful but at the same time
  780. has less magic.
  781. Rationale behind this is removal of dependency of non-contrib code on
  782. contrib applications.
  783. * The old cache URI syntax (e.g. ``"locmem://"``) is no longer supported. It
  784. still worked, even though it was not documented or officially supported. If
  785. you're still using it, please update to the current :setting:`CACHES` syntax.
  786. * The default ordering of ``Form`` fields in case of inheritance has changed to
  787. follow normal Python MRO. Fields are now discovered by iterating through the
  788. MRO in reverse with the topmost class coming last. This only affects you if
  789. you relied on the default field ordering while having fields defined on both
  790. the current class *and* on a parent ``Form``.
  791. * The ``required`` argument of
  792. :class:`~django.forms.extras.widgets.SelectDateWidget` has been removed.
  793. This widget now respects the form field's ``is_required`` attribute like
  794. other widgets.
  795. * :meth:`~django.db.models.query.QuerySet.select_related` now chains in the
  796. same way as other similar calls like ``prefetch_related``. That is,
  797. ``select_related('foo', 'bar')`` is equivalent to
  798. ``select_related('foo').select_related('bar')``. Previously the latter would
  799. have been equivalent to ``select_related('bar')``.
  800. * GeoDjango dropped support for GEOS < 3.1.
  801. * The ``init_connection_state`` method of database backends now executes in
  802. autocommit mode (unless you set :setting:`AUTOCOMMIT <DATABASE-AUTOCOMMIT>`
  803. to ``False``). If you maintain a custom database backend, you should check
  804. that method.
  805. * The ``django.db.backends.BaseDatabaseFeatures.allows_primary_key_0``
  806. attribute has been renamed to ``allows_auto_pk_0`` to better describe it.
  807. It's ``True`` for all database backends included with Django except MySQL
  808. which does allow primary keys with value 0. It only forbids *autoincrement*
  809. primary keys with value 0.
  810. .. _deprecated-features-1.7:
  811. Features deprecated in 1.7
  812. ==========================
  813. ``django.core.cache.get_cache``
  814. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  815. :func:`django.core.cache.get_cache` has been supplanted by
  816. :data:`django.core.cache.caches`.
  817. ``django.utils.dictconfig``/``django.utils.importlib``
  818. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  819. ``django.utils.dictconfig`` and ``django.utils.importlib`` were copies of
  820. respectively :mod:`logging.config` and :mod:`importlib` provided for Python
  821. versions prior to 2.7. They have been deprecated.
  822. ``django.utils.module_loading.import_by_path``
  823. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  824. The current :meth:`~django.utils.module_loading.import_by_path` function
  825. catches ``AttributeError``, ``ImportError`` and ``ValueError`` exceptions,
  826. and re-raises :exc:`~django.core.exceptions.ImproperlyConfigured`. Such
  827. exception masking makes it needlessly hard to diagnose circular import
  828. problems, because it makes it look like the problem comes from inside Django.
  829. It has been deprecated in favor of
  830. :meth:`~django.utils.module_loading.import_string`.
  831. ``django.utils.tzinfo``
  832. ~~~~~~~~~~~~~~~~~~~~~~~
  833. ``django.utils.tzinfo`` provided two :class:`~datetime.tzinfo` subclasses,
  834. ``LocalTimezone`` and ``FixedOffset``. They've been deprecated in favor of
  835. more correct alternatives provided by :mod:`django.utils.timezone`,
  836. :func:`django.utils.timezone.get_default_timezone` and
  837. :func:`django.utils.timezone.get_fixed_timezone`.
  838. ``django.utils.unittest``
  839. ~~~~~~~~~~~~~~~~~~~~~~~~~
  840. ``django.utils.unittest`` provided uniform access to the ``unittest2`` library
  841. on all Python versions. Since ``unittest2`` became the standard library's
  842. :mod:`unittest` module in Python 2.7, and Django 1.7 drops support for older
  843. Python versions, this module isn't useful anymore. It has been deprecated. Use
  844. :mod:`unittest` instead.
  845. ``django.utils.datastructures.SortedDict``
  846. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  847. As :class:`~collections.OrderedDict` was added to the standard library in
  848. Python 2.7, :class:`~django.utils.datastructures.SortedDict` is no longer
  849. needed and has been deprecated.
  850. Custom SQL location for models package
  851. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  852. Previously, if models were organized in a package (``myapp/models/``) rather
  853. than simply ``myapp/models.py``, Django would look for :ref:`initial SQL data
  854. <initial-sql>` in ``myapp/models/sql/``. This bug has been fixed so that Django
  855. will search ``myapp/sql/`` as documented. The old location will continue to
  856. work until Django 1.9.
  857. Reorganization of ``django.contrib.sites``
  858. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  859. ``django.contrib.sites`` provides reduced functionality when it isn't in
  860. :setting:`INSTALLED_APPS`. The app-loading refactor adds some constraints in
  861. that situation. As a consequence, two objects were moved, and the old
  862. locations are deprecated:
  863. * :class:`~django.contrib.sites.requests.RequestSite` now lives in
  864. ``django.contrib.sites.requests``.
  865. * :func:`~django.contrib.sites.shortcuts.get_current_site` now lives in
  866. ``django.contrib.sites.shortcuts``.
  867. ``declared_fieldsets`` attribute on ``ModelAdmin``
  868. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  869. ``ModelAdmin.declared_fieldsets`` has been deprecated. Despite being a private
  870. API, it will go through a regular deprecation path. This attribute was mostly
  871. used by methods that bypassed ``ModelAdmin.get_fieldsets()`` but this was
  872. considered a bug and has been addressed.
  873. Reorganization of ``django.contrib.contenttypes``
  874. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  875. Since ``django.contrib.contenttypes.generic`` defined both admin and model
  876. related objects an import of this module could trigger unexpected side effects.
  877. As a consequence, its contents were split into :mod:`~django.contrib.contenttypes`
  878. submodules and the ``django.contrib.contenttypes.generic`` module is deprecated:
  879. * :class:`~django.contrib.contenttypes.fields.GenericForeignKey` and
  880. :class:`~django.contrib.contenttypes.fields.GenericRelation` now live in
  881. :mod:`~django.contrib.contenttypes.fields`.
  882. * :class:`~django.contrib.contenttypes.forms.BaseGenericInlineFormSet` and
  883. :func:`~django.contrib.contenttypes.forms.generic_inlineformset_factory` now
  884. live in :mod:`~django.contrib.contenttypes.forms`.
  885. * :class:`~django.contrib.contenttypes.admin.GenericInlineModelAdmin`,
  886. :class:`~django.contrib.contenttypes.admin.GenericStackedInline` and
  887. :class:`~django.contrib.contenttypes.admin.GenericTabularInline` now live in
  888. :mod:`~django.contrib.contenttypes.admin`.
  889. ``syncdb``
  890. ~~~~~~~~~~
  891. The :djadmin:`syncdb` command has been deprecated in favor of the new :djadmin:`migrate`
  892. command. ``migrate`` takes the same arguments as ``syncdb`` used to plus a few
  893. more, so it's safe to just change the name you're calling and nothing else.
  894. ``util`` modules renamed to ``utils``
  895. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  896. The following instances of ``util.py`` in the Django codebase have been renamed
  897. to ``utils.py`` in an effort to unify all util and utils references:
  898. * ``django.contrib.admin.util``
  899. * ``django.contrib.gis.db.backends.util``
  900. * ``django.db.backends.util``
  901. * ``django.forms.util``
  902. ``get_formsets`` method on ``ModelAdmin``
  903. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  904. ``ModelAdmin.get_formsets`` has been deprecated in favor of the new
  905. :meth:`~django.contrib.admin.ModelAdmin.get_formsets_with_inlines`, in order to
  906. better handle the case of selecting showing inlines on a ``ModelAdmin``.
  907. ``IPAddressField``
  908. ~~~~~~~~~~~~~~~~~~
  909. The :class:`django.db.models.IPAddressField` and
  910. :class:`django.forms.IPAddressField` fields have been deprecated in favor of
  911. :class:`django.db.models.GenericIPAddressField` and
  912. :class:`django.forms.GenericIPAddressField`.
  913. ``BaseMemcachedCache._get_memcache_timeout`` method
  914. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  915. The ``BaseMemcachedCache._get_memcache_timeout()`` method has been renamed to
  916. ``get_backend_timeout()``. Despite being a private API, it will go through the
  917. normal deprecation.
  918. Natural key serialization options
  919. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  920. The ``--natural`` and ``-n`` options for :djadmin:`dumpdata` have been
  921. deprecated. Use :djadminopt:`--natural-foreign` instead.
  922. Similarly, the ``use_natural_keys`` argument for ``serializers.serialize()``
  923. has been deprecated. Use ``use_natural_foreign_keys`` instead.
  924. Merging of ``POST`` and ``GET`` arguments into ``WSGIRequest.REQUEST``
  925. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  926. It was already strongly suggested that you use ``GET`` and ``POST`` instead of
  927. ``REQUEST``, because the former are more explicit. The property ``REQUEST`` is
  928. deprecated and will be removed in Django 1.9.
  929. ``django.utils.datastructures.MergeDict`` class
  930. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  931. ``MergeDict`` exists primarily to support merging ``POST`` and ``GET``
  932. arguments into a ``REQUEST`` property on ``WSGIRequest``. To merge
  933. dictionaries, use ``dict.update()`` instead. The class ``MergeDict`` is
  934. deprecated and will be removed in Django 1.9.
  935. Language codes ``zh-cn``, ``zh-tw`` and ``fy-nl``
  936. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  937. The currently used language codes for Simplified Chinese ``zh-cn``,
  938. Traditional Chinese ``zh-tw`` and (Western) Frysian ``fy-nl`` are deprecated
  939. and should be replaced by the language codes ``zh-hans``, ``zh-hant`` and
  940. ``fy`` respectively. If you use these language codes, you should rename the
  941. locale directories and update your settings to reflect these changes. The
  942. deprecated language codes will be removed in Django 1.9.
  943. ``django.utils.functional.memoize`` function
  944. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  945. The function ``memoize`` is deprecated and should be replaced by the
  946. ``functools.lru_cache`` decorator (available from Python 3.2 onwards).
  947. Django ships a backport of this decorator for older Python versions and it's
  948. available at ``django.utils.lru_cache.lru_cache``. The deprecated function will
  949. be removed in Django 1.9.
  950. Geo Sitemaps
  951. ~~~~~~~~~~~~
  952. Google has retired support for the Geo Sitemaps format. Hence Django support
  953. for Geo Sitemaps is deprecated and will be removed in Django 1.8.
  954. Passing callable arguments to queryset methods
  955. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  956. Callable arguments for querysets were an undocumented feature that was
  957. unreliable. It's been deprecated and will be removed in Django 1.9.
  958. Callable arguments were evaluated when a queryset was constructed rather than
  959. when it was evaluated, thus this feature didn't offer any benefit compared to
  960. evaluating arguments before passing them to queryset and created confusion that
  961. the arguments may have been evaluated at query time.
  962. ``ADMIN_FOR`` setting
  963. ~~~~~~~~~~~~~~~~~~~~~
  964. The ``ADMIN_FOR`` feature, part of the admindocs, has been removed. You can
  965. remove the setting from your configuration at your convenience.
  966. ``SplitDateTimeWidget`` with ``DateTimeField``
  967. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  968. ``SplitDateTimeWidget`` support in :class:`~django.forms.DateTimeField` is
  969. deprecated, use ``SplitDateTimeWidget`` with
  970. :class:`~django.forms.SplitDateTimeField` instead.
  971. ``validate``
  972. ~~~~~~~~~~~~
  973. :djadmin:`validate` command is deprecated in favor of :djadmin:`check` command.
  974. ``django.core.management.BaseCommand``
  975. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  976. ``requires_model_validation`` is deprecated in favor of a new
  977. ``requires_system_checks`` flag. If the latter flag is missing, then the
  978. value of the former flag is used. Defining both ``requires_system_checks`` and
  979. ``requires_model_validation`` results in an error.
  980. The ``check()`` method has replaced the old ``validate()`` method.
  981. ``ModelAdmin.validator``
  982. ~~~~~~~~~~~~~~~~~~~~~~~~
  983. ``ModelAdmin.validator`` is deprecated in favor of new ``checks`` attribute.
  984. ``django.db.backends.DatabaseValidation.validate_field``
  985. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  986. This method is deprecated in favor of a new ``check_field`` method.
  987. The functionality required by ``check_field()`` is the same as that provided
  988. by ``validate_field()``, but the output format is different. Third-party database
  989. backends needing this functionality should modify their backends to provide an
  990. implementation of ``check_field()``.