1.7.txt 54 KB

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