1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +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:
Edward Henderson
2015-04-15 16:28:49 -06:00
committed by Tim Graham
parent adffff79a3
commit f8cc464452
26 changed files with 223 additions and 46 deletions

View File

@@ -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``
~~~~~~~~~~~~~

View File

@@ -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``
---------------------

View File

@@ -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``

View File

@@ -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``
-------------------------