mirror of
https://github.com/django/django.git
synced 2025-10-24 22:26:08 +00:00
Fixed #16501 -- Added an allow_unicode parameter to SlugField.
Thanks Flavio Curella and Berker Peksag for the initial patch.
This commit is contained in:
committed by
Tim Graham
parent
adffff79a3
commit
f8cc464452
@@ -875,6 +875,15 @@ For each field, we describe the default widget used if you don't specify
|
||||
This field is intended for use in representing a model
|
||||
:class:`~django.db.models.SlugField` in forms.
|
||||
|
||||
Takes an optional parameter:
|
||||
|
||||
.. attribute:: allow_unicode
|
||||
|
||||
.. versionadded:: 1.9
|
||||
|
||||
A boolean instructing the field to accept Unicode letters in addition
|
||||
to ASCII letters. Defaults to ``False``.
|
||||
|
||||
``TimeField``
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
|
||||
@@ -1012,6 +1012,13 @@ It is often useful to automatically prepopulate a SlugField based on the value
|
||||
of some other value. You can do this automatically in the admin using
|
||||
:attr:`~django.contrib.admin.ModelAdmin.prepopulated_fields`.
|
||||
|
||||
.. attribute:: SlugField.allow_unicode
|
||||
|
||||
.. versionadded:: 1.9
|
||||
|
||||
If ``True``, the field accepts Unicode letters in addition to ASCII
|
||||
letters. Defaults to ``False``.
|
||||
|
||||
``SmallIntegerField``
|
||||
---------------------
|
||||
|
||||
|
||||
@@ -836,11 +836,11 @@ appropriate entities.
|
||||
.. module:: django.utils.text
|
||||
:synopsis: Text manipulation.
|
||||
|
||||
.. function:: slugify
|
||||
.. function:: slugify(allow_unicode=False)
|
||||
|
||||
Converts to ASCII. Converts spaces to hyphens. Removes characters that
|
||||
aren't alphanumerics, underscores, or hyphens. Converts to lowercase. Also
|
||||
strips leading and trailing whitespace.
|
||||
Converts to ASCII if ``allow_unicode`` is ``False`` (default). Converts spaces to
|
||||
hyphens. Removes characters that aren't alphanumerics, underscores, or
|
||||
hyphens. Converts to lowercase. Also strips leading and trailing whitespace.
|
||||
|
||||
For example::
|
||||
|
||||
@@ -849,6 +849,17 @@ appropriate entities.
|
||||
If ``value`` is ``"Joel is a slug"``, the output will be
|
||||
``"joel-is-a-slug"``.
|
||||
|
||||
You can set the ``allow_unicode`` parameter to ``True``, if you want to
|
||||
allow Unicode characters::
|
||||
|
||||
slugify(value, allow_unicode=True)
|
||||
|
||||
If ``value`` is ``"你好 World"``, the output will be ``"你好-world"``.
|
||||
|
||||
.. versionchanged:: 1.9
|
||||
|
||||
The ``allow_unicode`` parameter was added.
|
||||
|
||||
.. _time-zone-selection-functions:
|
||||
|
||||
``django.utils.timezone``
|
||||
|
||||
@@ -183,6 +183,16 @@ to, or in lieu of custom ``field.clean()`` methods.
|
||||
A :class:`RegexValidator` instance that ensures a value consists of only
|
||||
letters, numbers, underscores or hyphens.
|
||||
|
||||
``validate_unicode_slug``
|
||||
-------------------------
|
||||
|
||||
.. data:: validate_unicode_slug
|
||||
|
||||
.. versionadded:: 1.9
|
||||
|
||||
A :class:`RegexValidator` instance that ensures a value consists of only
|
||||
Unicode letters, numbers, underscores, or hyphens.
|
||||
|
||||
``validate_ipv4_address``
|
||||
-------------------------
|
||||
|
||||
|
||||
@@ -308,6 +308,10 @@ Forms
|
||||
* You can now :ref:`specify keyword arguments <custom-formset-form-kwargs>`
|
||||
that you want to pass to the constructor of forms in a formset.
|
||||
|
||||
* :class:`~django.forms.SlugField` now accepts an
|
||||
:attr:`~django.forms.SlugField.allow_unicode` argument to allow Unicode
|
||||
characters in slugs.
|
||||
|
||||
* :class:`~django.forms.CharField` now accepts a
|
||||
:attr:`~django.forms.CharField.strip` argument to strip input data of leading
|
||||
and trailing whitespace. As this defaults to ``True`` this is different
|
||||
@@ -426,6 +430,10 @@ Models
|
||||
* Added the :class:`~django.db.models.functions.Now` database function, which
|
||||
returns the current date and time.
|
||||
|
||||
* :class:`~django.db.models.SlugField` now accepts an
|
||||
:attr:`~django.db.models.SlugField.allow_unicode` argument to allow Unicode
|
||||
characters in slugs.
|
||||
|
||||
CSRF
|
||||
^^^^
|
||||
|
||||
@@ -536,6 +544,9 @@ Validators
|
||||
* :class:`~django.core.validators.EmailValidator` now limits the length of
|
||||
domain name labels to 63 characters per :rfc:`1034`.
|
||||
|
||||
* Added :func:`~django.core.validators.validate_unicode_slug` to validate slugs
|
||||
that may contain Unicode characters.
|
||||
|
||||
Backwards incompatible changes in 1.9
|
||||
=====================================
|
||||
|
||||
|
||||
Reference in New Issue
Block a user