From a58145e20f796232ef0143f28ecb0c31dbfea92e Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Mon, 28 Jan 2013 07:46:30 +0000 Subject: Note auto_now, auto_now_add behavior. Refs #622. --- docs/api-guide/fields.md | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'docs/api-guide/fields.md') diff --git a/docs/api-guide/fields.md b/docs/api-guide/fields.md index 5bc8f7f7..e43282ce 100644 --- a/docs/api-guide/fields.md +++ b/docs/api-guide/fields.md @@ -193,6 +193,16 @@ A date and time representation. Corresponds to `django.db.models.fields.DateTimeField` +When using `ModelSerializer` or `HyperlinkedModelSerializer`, note that any model fields with `auto_now=True` or `auto_now_add=True` will use serializer fields that are `read_only=True` by default. + +If you want to override this behavior, you'll need to declare the `DateTimeField` explicitly on the serializer. For example: + + class CommentSerializer(serializers.ModelSerializer): + created = serializers.DateTimeField() + + class Meta: + model = Comment + ## IntegerField An integer representation. -- cgit v1.2.3 From 1929159db1b45ef28d1f7fdf0bea9d0867af13f3 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Tue, 29 Jan 2013 09:15:08 +0000 Subject: Docs tweaks. --- docs/api-guide/fields.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'docs/api-guide/fields.md') diff --git a/docs/api-guide/fields.md b/docs/api-guide/fields.md index e43282ce..3f8a36e2 100644 --- a/docs/api-guide/fields.md +++ b/docs/api-guide/fields.md @@ -240,7 +240,9 @@ Signature and validation is the same as with `FileField`. --- **Note:** `FileFields` and `ImageFields` are only suitable for use with MultiPartParser, since e.g. json doesn't support file uploads. -Django's regular [FILE_UPLOAD_HANDLERS] are used for handling uploaded files. +Django's regular [FILE_UPLOAD_HANDLERS] are used for handling uploaded files. + +--- [cite]: https://docs.djangoproject.com/en/dev/ref/forms/api/#django.forms.Form.cleaned_data [FILE_UPLOAD_HANDLERS]: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FILE_UPLOAD_HANDLERS -- cgit v1.2.3 From 5a5df18d182d43d993da8f0b5d4a8888e868fcae Mon Sep 17 00:00:00 2001 From: Andreas Pelme Date: Thu, 14 Feb 2013 21:19:51 +0100 Subject: Added a serializer TimeField --- docs/api-guide/fields.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'docs/api-guide/fields.md') diff --git a/docs/api-guide/fields.md b/docs/api-guide/fields.md index 3f8a36e2..8c28273b 100644 --- a/docs/api-guide/fields.md +++ b/docs/api-guide/fields.md @@ -199,10 +199,16 @@ If you want to override this behavior, you'll need to declare the `DateTimeField class CommentSerializer(serializers.ModelSerializer): created = serializers.DateTimeField() - + class Meta: model = Comment +## TimeField + +A time representation. + +Corresponds to `django.db.models.fields.TimeField` + ## IntegerField An integer representation. -- cgit v1.2.3 From cd7f552540778a744f51ade76aa4f8067eaf303a Mon Sep 17 00:00:00 2001 From: Wiliam Souza Date: Tue, 26 Feb 2013 10:43:33 -0300 Subject: Fixed a typo WritableField field name in docs --- docs/api-guide/fields.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/api-guide/fields.md') diff --git a/docs/api-guide/fields.md b/docs/api-guide/fields.md index 8c28273b..d7f9197f 100644 --- a/docs/api-guide/fields.md +++ b/docs/api-guide/fields.md @@ -102,7 +102,7 @@ You can customize this behavior by overriding the `.to_native(self, value)` met ## WritableField -A field that supports both read and write operations. By itself `WriteableField` does not perform any translation of input values into a given type. You won't typically use this field directly, but you may want to override it and implement the `.to_native(self, value)` and `.from_native(self, value)` methods. +A field that supports both read and write operations. By itself `WritableField` does not perform any translation of input values into a given type. You won't typically use this field directly, but you may want to override it and implement the `.to_native(self, value)` and `.from_native(self, value)` methods. ## ModelField -- cgit v1.2.3 From 9157db5da0b5601793d1a9f24e9cb10670a82be2 Mon Sep 17 00:00:00 2001 From: Stephan Groß Date: Tue, 26 Feb 2013 11:09:54 +0100 Subject: Add better date / datetime validation (pull 2) addition to #631 with update to master + timefield support --- docs/api-guide/fields.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'docs/api-guide/fields.md') diff --git a/docs/api-guide/fields.md b/docs/api-guide/fields.md index d7f9197f..abacc1b8 100644 --- a/docs/api-guide/fields.md +++ b/docs/api-guide/fields.md @@ -185,12 +185,20 @@ Corresponds to `django.forms.fields.RegexField` A date representation. +Uses `DATE_INPUT_FORMATS` to validate date. + +Optionally takes `format` as parameter to replace the matching pattern. + Corresponds to `django.db.models.fields.DateField` ## DateTimeField A date and time representation. +Uses `DATETIME_INPUT_FORMATS` to validate date_time. + +Optionally takes `format` as parameter to replace the matching pattern. + Corresponds to `django.db.models.fields.DateTimeField` When using `ModelSerializer` or `HyperlinkedModelSerializer`, note that any model fields with `auto_now=True` or `auto_now_add=True` will use serializer fields that are `read_only=True` by default. @@ -207,6 +215,10 @@ If you want to override this behavior, you'll need to declare the `DateTimeField A time representation. +Uses `TIME_INPUT_FORMATS` to validate time. + +Optionally takes `format` as parameter to replace the matching pattern. + Corresponds to `django.db.models.fields.TimeField` ## IntegerField -- cgit v1.2.3 From a9d36d4726fc8eea02184b089ee6ed1d02e4c75e Mon Sep 17 00:00:00 2001 From: Stephan Groß Date: Fri, 1 Mar 2013 15:03:27 +0100 Subject: Add docs update - part 1 --- docs/api-guide/fields.md | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'docs/api-guide/fields.md') diff --git a/docs/api-guide/fields.md b/docs/api-guide/fields.md index abacc1b8..c1f3c051 100644 --- a/docs/api-guide/fields.md +++ b/docs/api-guide/fields.md @@ -185,18 +185,20 @@ Corresponds to `django.forms.fields.RegexField` A date representation. -Uses `DATE_INPUT_FORMATS` to validate date. - Optionally takes `format` as parameter to replace the matching pattern. Corresponds to `django.db.models.fields.DateField` +**Signature:** `DateField(input_formats=None, output_format=False)` + + - `input_formats` designates which input formats are supported. This will override the `DATE_INPUT_FORMATS` + + - `output_format` designates which output format will be used. This will override the `DATE_OUTPUT_FORMAT` + ## DateTimeField A date and time representation. -Uses `DATETIME_INPUT_FORMATS` to validate date_time. - Optionally takes `format` as parameter to replace the matching pattern. Corresponds to `django.db.models.fields.DateTimeField` @@ -211,16 +213,26 @@ If you want to override this behavior, you'll need to declare the `DateTimeField class Meta: model = Comment +**Signature:** `DateTimeField(input_formats=None, output_format=False)` + + - `input_formats` designates which input formats are supported. This will override the `DATETIME_INPUT_FORMATS` + + - `output_format` designates which output format will be used. This will override the `DATETIME_OUTPUT_FORMAT` + ## TimeField A time representation. -Uses `TIME_INPUT_FORMATS` to validate time. - Optionally takes `format` as parameter to replace the matching pattern. Corresponds to `django.db.models.fields.TimeField` +**Signature:** `TimeField(input_formats=None, output_format=False)` + + - `input_formats` designates which input formats are supported. This will override the `TIME_INPUT_FORMATS` + + - `output_format` designates which output format will be used. This will override the `TIME_OUTPUT_FORMAT` + ## IntegerField An integer representation. -- cgit v1.2.3 From 4f7b028a0a983b79ebca63b2ba48ce97e7a06175 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Tue, 5 Mar 2013 20:57:35 +0000 Subject: Updating docs --- docs/api-guide/fields.md | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) (limited to 'docs/api-guide/fields.md') diff --git a/docs/api-guide/fields.md b/docs/api-guide/fields.md index c1f3c051..68e619a0 100644 --- a/docs/api-guide/fields.md +++ b/docs/api-guide/fields.md @@ -181,26 +181,10 @@ Corresponds to `django.forms.fields.RegexField` **Signature:** `RegexField(regex, max_length=None, min_length=None)` -## DateField - -A date representation. - -Optionally takes `format` as parameter to replace the matching pattern. - -Corresponds to `django.db.models.fields.DateField` - -**Signature:** `DateField(input_formats=None, output_format=False)` - - - `input_formats` designates which input formats are supported. This will override the `DATE_INPUT_FORMATS` - - - `output_format` designates which output format will be used. This will override the `DATE_OUTPUT_FORMAT` - ## DateTimeField A date and time representation. -Optionally takes `format` as parameter to replace the matching pattern. - Corresponds to `django.db.models.fields.DateTimeField` When using `ModelSerializer` or `HyperlinkedModelSerializer`, note that any model fields with `auto_now=True` or `auto_now_add=True` will use serializer fields that are `read_only=True` by default. @@ -213,11 +197,25 @@ If you want to override this behavior, you'll need to declare the `DateTimeField class Meta: model = Comment -**Signature:** `DateTimeField(input_formats=None, output_format=False)` +**Signature:** `DateTimeField(format=None, input_formats=None)` + +* `format` - A string representing the output format. If not specified, the `DATETIME_FORMAT` setting will be used, which defaults to `'iso8601'`. +* `input_formats` - A list of strings representing the input formats which may be used to parse the date. If not specified, the `DATETIME_INPUT_FORMATS` setting will be used, which defaults to `['iso8601']`. + +DateTime format strings may either be [python strftime formats][strftime] which explicitly specifiy the format, or the special string `'is8601'`, which indicates that [ISO 8601][iso8601] style datetimes should be used. (eg `'2013-01-29T12:34:56.000000'`) + +## DateField + +A date representation. + +Corresponds to `django.db.models.fields.DateField` + +**Signature:** `DateField(format=None, input_formats=None)` - - `input_formats` designates which input formats are supported. This will override the `DATETIME_INPUT_FORMATS` +* `format` - A string representing the output format. If not specified, the `DATE_FORMAT` setting will be used, which defaults to `'iso8601'`. +* `input_formats` - A list of strings representing the input formats which may be used to parse the date. If not specified, the `DATE_INPUT_FORMATS` setting will be used, which defaults to `['iso8601']`. - - `output_format` designates which output format will be used. This will override the `DATETIME_OUTPUT_FORMAT` +Date format strings may either be [python strftime formats][strftime] which explicitly specifiy the format, or the special string `'is8601'`, which indicates that [ISO 8601][iso8601] style dates should be used. (eg `'2013-01-29'`) ## TimeField @@ -227,11 +225,12 @@ Optionally takes `format` as parameter to replace the matching pattern. Corresponds to `django.db.models.fields.TimeField` -**Signature:** `TimeField(input_formats=None, output_format=False)` +**Signature:** `TimeField(format=None, input_formats=None)` - - `input_formats` designates which input formats are supported. This will override the `TIME_INPUT_FORMATS` +* `format` - A string representing the output format. If not specified, the `TIME_FORMAT` setting will be used, which defaults to `'iso8601'`. +* `input_formats` - A list of strings representing the input formats which may be used to parse the date. If not specified, the `TIME_INPUT_FORMATS` setting will be used, which defaults to `['iso8601']`. - - `output_format` designates which output format will be used. This will override the `TIME_OUTPUT_FORMAT` +Time format strings may either be [python strftime formats][strftime] which explicitly specifiy the format, or the special string `'is8601'`, which indicates that [ISO 8601][iso8601] style times should be used. (eg `'12:34:56.000000'`) ## IntegerField @@ -276,3 +275,5 @@ Django's regular [FILE_UPLOAD_HANDLERS] are used for handling uploaded files. [cite]: https://docs.djangoproject.com/en/dev/ref/forms/api/#django.forms.Form.cleaned_data [FILE_UPLOAD_HANDLERS]: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FILE_UPLOAD_HANDLERS +[strftime]: http://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior +[iso8601]: http://www.w3.org/TR/NOTE-datetime -- cgit v1.2.3 From 1106596c80218569a56ff5ea04d759e3d0c541dd Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Wed, 6 Mar 2013 12:19:39 +0000 Subject: Clean ups to datetime formatting --- docs/api-guide/fields.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'docs/api-guide/fields.md') diff --git a/docs/api-guide/fields.md b/docs/api-guide/fields.md index 68e619a0..9a745cf1 100644 --- a/docs/api-guide/fields.md +++ b/docs/api-guide/fields.md @@ -2,7 +2,7 @@ # Serializer fields -> Each field in a Form class is responsible not only for validating data, but also for "cleaning" it -- normalizing it to a consistent format. +> Each field in a Form class is responsible not only for validating data, but also for "cleaning" it — normalizing it to a consistent format. > > — [Django documentation][cite] @@ -199,10 +199,10 @@ If you want to override this behavior, you'll need to declare the `DateTimeField **Signature:** `DateTimeField(format=None, input_formats=None)` -* `format` - A string representing the output format. If not specified, the `DATETIME_FORMAT` setting will be used, which defaults to `'iso8601'`. -* `input_formats` - A list of strings representing the input formats which may be used to parse the date. If not specified, the `DATETIME_INPUT_FORMATS` setting will be used, which defaults to `['iso8601']`. +* `format` - A string representing the output format. If not specified, the `DATETIME_FORMAT` setting will be used, which defaults to `'iso-8601'`. +* `input_formats` - A list of strings representing the input formats which may be used to parse the date. If not specified, the `DATETIME_INPUT_FORMATS` setting will be used, which defaults to `['iso-8601']`. -DateTime format strings may either be [python strftime formats][strftime] which explicitly specifiy the format, or the special string `'is8601'`, which indicates that [ISO 8601][iso8601] style datetimes should be used. (eg `'2013-01-29T12:34:56.000000'`) +DateTime format strings may either be [python strftime formats][strftime] which explicitly specifiy the format, or the special string `'iso-8601'`, which indicates that [ISO 8601][iso8601] style datetimes should be used. (eg `'2013-01-29T12:34:56.000000'`) ## DateField @@ -212,10 +212,10 @@ Corresponds to `django.db.models.fields.DateField` **Signature:** `DateField(format=None, input_formats=None)` -* `format` - A string representing the output format. If not specified, the `DATE_FORMAT` setting will be used, which defaults to `'iso8601'`. -* `input_formats` - A list of strings representing the input formats which may be used to parse the date. If not specified, the `DATE_INPUT_FORMATS` setting will be used, which defaults to `['iso8601']`. +* `format` - A string representing the output format. If not specified, the `DATE_FORMAT` setting will be used, which defaults to `'iso-8601'`. +* `input_formats` - A list of strings representing the input formats which may be used to parse the date. If not specified, the `DATE_INPUT_FORMATS` setting will be used, which defaults to `['iso-8601']`. -Date format strings may either be [python strftime formats][strftime] which explicitly specifiy the format, or the special string `'is8601'`, which indicates that [ISO 8601][iso8601] style dates should be used. (eg `'2013-01-29'`) +Date format strings may either be [python strftime formats][strftime] which explicitly specifiy the format, or the special string `'iso-8601'`, which indicates that [ISO 8601][iso8601] style dates should be used. (eg `'2013-01-29'`) ## TimeField @@ -227,10 +227,10 @@ Corresponds to `django.db.models.fields.TimeField` **Signature:** `TimeField(format=None, input_formats=None)` -* `format` - A string representing the output format. If not specified, the `TIME_FORMAT` setting will be used, which defaults to `'iso8601'`. -* `input_formats` - A list of strings representing the input formats which may be used to parse the date. If not specified, the `TIME_INPUT_FORMATS` setting will be used, which defaults to `['iso8601']`. +* `format` - A string representing the output format. If not specified, the `TIME_FORMAT` setting will be used, which defaults to `'iso-8601'`. +* `input_formats` - A list of strings representing the input formats which may be used to parse the date. If not specified, the `TIME_INPUT_FORMATS` setting will be used, which defaults to `['iso-8601']`. -Time format strings may either be [python strftime formats][strftime] which explicitly specifiy the format, or the special string `'is8601'`, which indicates that [ISO 8601][iso8601] style times should be used. (eg `'12:34:56.000000'`) +Time format strings may either be [python strftime formats][strftime] which explicitly specifiy the format, or the special string `'iso-8601'`, which indicates that [ISO 8601][iso8601] style times should be used. (eg `'12:34:56.000000'`) ## IntegerField -- cgit v1.2.3