diff options
| author | José Padilla | 2015-02-06 01:09:19 -0400 |
|---|---|---|
| committer | José Padilla | 2015-02-06 01:09:19 -0400 |
| commit | 7f801b9a01fa7df3b081ddec803bd0d34cc3b35b (patch) | |
| tree | b51d0381fecc50c4cd088a4cc4bdd5f61806c6e2 /docs/api-guide/fields.md | |
| parent | 09488ad4da321f5f15d6e3df348869b8f2116b4a (diff) | |
| download | django-rest-framework-7f801b9a01fa7df3b081ddec803bd0d34cc3b35b.tar.bz2 | |
Add trim_whitespace to CharField #2517
If set to `True` then leading and trailing
whitespace is trimmed. Defaults to `True`.
Diffstat (limited to 'docs/api-guide/fields.md')
| -rw-r--r-- | docs/api-guide/fields.md | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/docs/api-guide/fields.md b/docs/api-guide/fields.md index 10291c12..9c33974f 100644 --- a/docs/api-guide/fields.md +++ b/docs/api-guide/fields.md @@ -138,11 +138,12 @@ A text representation. Optionally validates the text to be shorter than `max_len Corresponds to `django.db.models.fields.CharField` or `django.db.models.fields.TextField`. -**Signature:** `CharField(max_length=None, min_length=None, allow_blank=False)` +**Signature:** `CharField(max_length=None, min_length=None, allow_blank=False, trim_whitespace=True)` - `max_length` - Validates that the input contains no more than this number of characters. - `min_length` - Validates that the input contains no fewer than this number of characters. - `allow_blank` - If set to `True` then the empty string should be considered a valid value. If set to `False` then the empty string is considered invalid and will raise a validation error. Defaults to `False`. +- `trim_whitespace` - If set to `True` then leading and trailing whitespace is trimmed. Defaults to `True`. The `allow_null` option is also available for string fields, although its usage is discouraged in favor of `allow_blank`. It is valid to set both `allow_blank=True` and `allow_null=True`, but doing so means that there will be two differing types of empty value permissible for string representations, which can lead to data inconsistencies and subtle application bugs. @@ -524,7 +525,7 @@ As an example, let's create a field that can be used represent the class name of # We pass the object instance onto `to_representation`, # not just the field attribute. return obj - + def to_representation(self, obj): """ Serialize the object's class name. |
