======================== Django 2.1 release notes ======================== *August 1, 2018* Welcome to Django 2.1! These release notes cover the :ref:`new features `, as well as some :ref:`backwards incompatible changes ` you'll want to be aware of when upgrading from Django 2.0 or earlier. We've :ref:`dropped some features` that have reached the end of their deprecation cycle, and we've :ref:`begun the deprecation process for some features `. See the :doc:`/howto/upgrade-version` guide if you're updating an existing project. Python compatibility ==================== Django 2.1 supports Python 3.5, 3.6, and 3.7. Django 2.0 is the last version to support Python 3.4. We **highly recommend** and only officially support the latest release of each series. .. _whats-new-2.1: What's new in Django 2.1 ======================== Model "view" permission ----------------------- A "view" permission is added to the model :attr:`Meta.default_permissions `. The new permissions will be created automatically when running :djadmin:`migrate`. This allows giving users read-only access to models in the admin. :meth:`.ModelAdmin.has_view_permission` is new. The implementation is backwards compatible in that there isn't a need to assign the "view" permission to allow users who have the "change" permission to edit objects. There are a couple of :ref:`backwards incompatible considerations `. Minor features -------------- :mod:`django.contrib.admin` ~~~~~~~~~~~~~~~~~~~~~~~~~~~ * :attr:`.ModelAdmin.search_fields` now accepts any lookup such as ``field__exact``. * jQuery is upgraded from version 2.2.3 to 3.3.1. * The new :meth:`.ModelAdmin.delete_queryset` method allows customizing the deletion process of the "delete selected objects" action. * You can now :ref:`override the default admin site `. * The new :attr:`.ModelAdmin.sortable_by` attribute and :meth:`.ModelAdmin.get_sortable_by` method allow limiting the columns that can be sorted in the change list page. * The ``admin_order_field`` attribute for elements in :attr:`.ModelAdmin.list_display` may now be a query expression. * The new :meth:`.ModelAdmin.get_deleted_objects()` method allows customizing the deletion process of the delete view and the "delete selected" action. * The ``actions.html``, ``change_list_results.html``, ``date_hierarchy.html``, ``pagination.html``, ``prepopulated_fields_js.html``, ``search_form.html``, and ``submit_line.html`` templates can now be :ref:`overridden per app or per model ` (besides overridden globally). * The admin change list and change form object tools can now be :ref:`overridden per app, per model, or globally ` with ``change_list_object_tools.html`` and ``change_form_object_tools.html`` templates. * :meth:`.InlineModelAdmin.has_add_permission` is now passed the parent object as the second positional argument, ``obj``. * Admin actions may now :ref:`specify permissions ` to limit their availability to certain users. :mod:`django.contrib.auth` ~~~~~~~~~~~~~~~~~~~~~~~~~~ * :djadmin:`createsuperuser` now gives a prompt to allow bypassing the :setting:`AUTH_PASSWORD_VALIDATORS` checks. :mod:`django.contrib.gis` ~~~~~~~~~~~~~~~~~~~~~~~~~ * The new :meth:`.GEOSGeometry.buffer_with_style` method is a version of :meth:`~.GEOSGeometry.buffer` that allows customizing the style of the buffer. * :class:`~django.contrib.gis.forms.widgets.OpenLayersWidget` is now based on OpenLayers 4.6.5 (previously 3.20.1). :mod:`django.contrib.sessions` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Added the :setting:`SESSION_COOKIE_SAMESITE` setting to set the ``SameSite`` cookie flag on session cookies. Cache ~~~~~ * The :ref:`local-memory cache backend ` now uses a least-recently-used (LRU) culling strategy rather than a pseudo-random one. * The new :meth:`~django.core.caches.cache.touch` method of the :ref:`low-level cache API ` updates the timeout of cache keys. CSRF ~~~~ * Added the :setting:`CSRF_COOKIE_SAMESITE` setting to set the ``SameSite`` cookie flag on CSRF cookies. Forms ~~~~~ * The widget for ``ImageField`` now renders with the HTML attribute ``accept="image/*"``. Internationalization ~~~~~~~~~~~~~~~~~~~~ * Added the :meth:`~django.utils.translation.get_supported_language_variant` function. * Untranslated strings for territorial language variants now use the translations of the generic language. For example, untranslated ``pt_BR`` strings use ``pt`` translations. Management Commands ~~~~~~~~~~~~~~~~~~~ * The new :option:`inspectdb --include-views` option allows creating models for database views. * The :class:`~django.core.management.BaseCommand` class now uses a custom help formatter so that the standard options like ``--verbosity`` or ``--settings`` appear last in the help output, giving a more prominent position to subclassed command's options. Migrations ~~~~~~~~~~ * Added support for serialization of ``functools.partialmethod`` objects. * To support frozen environments, migrations may be loaded from ``.pyc`` files. Models ~~~~~~ * Models can now use ``__init_subclass__()`` from :pep:`487`. * A ``BinaryField`` may now be set to ``editable=True`` if you wish to include it in model forms. * A number of new text database functions are added: :class:`~django.db.models.functions.Chr`, :class:`~django.db.models.functions.Left`, :class:`~django.db.models.functions.LPad`, :class:`~django.db.models.functions.LTrim`, :class:`~django.db.models.functions.Ord`, :class:`~django.db.models.functions.Repeat`, :class:`~django.db.models.functions.Replace`, :class:`~django.db.models.functions.Right`, :class:`~django.db.models.functions.RPad`, :class:`~django.db.models.functions.RTrim`, and :class:`~django.db.models.functions.Trim`. * The new :class:`~django.db.models.functions.TruncWeek` function truncates :class:`~django.db.models.DateField` and :class:`~django.db.models.DateTimeField` to the Monday of a week. * Query expressions can now be negated using a minus sign. * :meth:`.QuerySet.order_by` and :meth:`distinct(*fields) <.QuerySet.distinct>` now support using field transforms. * :class:`~django.db.models.BooleanField` can now be ``null=True``. This is encouraged instead of :class:`~django.db.models.NullBooleanField`, which will likely be deprecated in the future. * The new :meth:`.QuerySet.explain` method displays the database's execution plan of a queryset's query. * :meth:`.QuerySet.raw` now supports :meth:`~.QuerySet.prefetch_related`. Requests and Responses ~~~~~~~~~~~~~~~~~~~~~~ * Added :meth:`.HttpRequest.get_full_path_info`. * Added the ``samesite`` argument to :meth:`.HttpResponse.set_cookie` to allow setting the ``SameSite`` cookie flag. * The new ``as_attachment`` argument for :class:`~django.http.FileResponse` sets the ``Content-Disposition`` header to make the browser ask if the user wants to download the file. ``FileResponse`` also tries to set the ``Content-Type`` and ``Content-Length`` headers where appropriate. Templates ~~~~~~~~~ * The new :tfilter:`json_script` filter safely outputs a Python object as JSON, wrapped in a ``