James Cleveland
4fc3b1ba56
Add timedelta encoder to the JSONEncoder class.
...
Whilst this commit adds *encoding* of timedeltas to a string of a floating
point value of the seconds, you must add your own serializer field for
whatever timedelta model field you are using. This is because Django doesn't
support any kind of timedelta field out-of-the-box, so you have to either
implement your own or use django-timedelta.
If this is the case and you want to serialise timedelta input, you will have
to implement your own special field to use for the timedelta, which is not
included in core as it is based on a 3rd party library. Here is an example:
import datetime
import timedelta
from django import forms
from django.core import validators
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _
from rest_framework.fields import WritableField
class TimedeltaField(WritableField):
type_name = 'TimedeltaField'
form_field_class = forms.FloatField
default_error_messages = {
'invalid': _("'%s' value must be in seconds."),
}
def from_native(self, value):
if value in validators.EMPTY_VALUES:
return None
try:
return datetime.timedelta(seconds=float(value))
except (TypeError, ValueError):
msg = self.error_messages['invalid'] % value
raise ValidationError(msg)
Which is based on the FloatField. This field can then be used in
your serializer like this:
from yourapp.fields import TimedeltaField
class YourSerializer(serializers.ModelSerializer):
duration = TimedeltaField()
2013-01-15 13:08:52 +00:00
Stephan Groß
e32aaa29b8
Add @shezi thanks!
2013-01-15 14:00:32 +01:00
Stephan Groß
4a4759dacb
Merge pull request #583 from shezi/master
...
Fixed a minor template bug
2013-01-15 04:58:44 -08:00
Johannes Spielmann
e67b23f1ac
correcting template: closing tag was missing
2013-01-15 13:46:41 +01:00
Tom Christie
da6b9576c5
Update docstrings
2013-01-15 10:51:10 +00:00
Tom Christie
79f635e0dd
Modify tutorial to work with pygments 1.6rc. Fixes #581 .
2013-01-15 09:33:24 +00:00
Tom Christie
190473f508
Tweak messagepack links
2013-01-14 17:38:45 +00:00
Tom Christie
a7e7c441a4
Add link to @mjumbewu's CSV package
2013-01-14 17:38:32 +00:00
Tom Christie
191135d7b0
Version 2.1.16
2013-01-14 09:20:44 +00:00
Tom Christie
cae9a334ce
Merge pull request #578 from Wackerbarth/tutorial
...
Format extensions have already been introduced.
2013-01-13 11:03:18 -08:00
Richard Wackerbarth
08943c3e0a
Format extensions have already been introduced.
...
If format extensions are used,
they must be used in the creation of the
reverse URLs.
2013-01-13 12:09:49 -06:00
Stephan Groß
9d47c32f44
Merge pull request #577 from Wackerbarth/tutorial
...
A minor gramatical correction
2013-01-12 11:37:38 -08:00
Richard Wackerbarth
0987bed2f7
Minor gramatical correction
2013-01-12 12:36:21 -06:00
Stephan Groß
da85bb1ab3
Update django-filter link to pypi
2013-01-12 14:31:40 +01:00
Stephan Groß
e0440e609b
Update django-filter link to pypi
2013-01-12 14:28:16 +01:00
Tom Christie
25a463be73
Update release notes.
2013-01-12 10:07:11 +00:00
Tom Christie
d9acec3e6d
PK fields should only be read-only if they are an AutoField. Fixes #563
2013-01-12 09:43:14 +00:00
Tom Christie
73c4e5c460
auto_now and auto_now_add fields should be read only by default
2013-01-12 09:43:14 +00:00
Stephan Groß
919c5e1e01
Fix typo in permission_classes
2013-01-11 20:26:44 +01:00
Tom Christie
c09a579851
Added @wackerbarth. Thanks!
2013-01-11 08:57:06 +00:00
Tom Christie
6e1fe0a818
Merge pull request #573 from Wackerbarth/tutorial
...
Make the whitespace uniform
2013-01-11 00:54:17 -08:00
Richard Wackerbarth
7dd5c56f22
Make the whitespace uniform
2013-01-10 16:16:30 -06:00
Tom Christie
7ae1111d02
Merge pull request #550 from Wackerbarth/tutorial
...
Revised Tutorial
2013-01-10 14:00:10 -08:00
Richard Wackerbarth
12efd78fcf
Bringing up the Web API
2013-01-10 15:37:49 -06:00
Richard Wackerbarth
8efd9563a6
Some comment on the tutorial repository
2013-01-10 15:37:33 -06:00
Richard Wackerbarth
674c9029c1
Imply an additional element in infinite lists
...
This is to allow the addition of elements without
having to change existing lines of code
2013-01-10 15:37:15 -06:00
Tom Christie
c4e33d8a75
Merge pull request #572 from juanriaza/master
...
Unused imports
2013-01-10 06:57:54 -08:00
Juan Riaza
268f60999c
unused imports
2013-01-10 15:48:22 +01:00
Tom Christie
cb235977f6
Include CSRF note in SessionAuthentication docs.
2013-01-09 09:22:23 +00:00
Mark Shirley
394a26f833
Merge pull request #553 from maspwr/null-one-to-one
...
Handle ObjectDoesNotExist exceptions when serializing null reverse one-to-one
2013-01-08 08:40:00 -08:00
Mark Aaron Shirley
b298bf53f3
Update release notes
2013-01-08 08:35:41 -08:00
Mark Aaron Shirley
81691ff900
Merge remote-tracking branch 'upstream/master' into null-one-to-one
2013-01-08 08:33:01 -08:00
Tom Christie
431ced66e4
Merge pull request #566 from mjtamlyn/patch-1
...
ObtainAuthToken pluggable Serializer.
2013-01-08 07:38:18 -08:00
Tom Christie
37a8458687
Merge branch 'master' of https://github.com/tomchristie/django-rest-framework
2013-01-08 15:05:34 +00:00
Tom Christie
c1f194b0a5
Fix inconsistent view_name logic. Fixes #567 .
2013-01-08 15:03:14 +00:00
Marc Tamlyn
49cd5e59a8
ObtainAuthToken pluggable Serializer.
...
It should have serializer_class in the same way as any other API view.
2013-01-08 12:20:01 +00:00
Stephan Groß
ae139cb06f
Merge pull request #565 from mjtamlyn/patch-1
...
Fix reference to BasicAuthentication in settings.
2013-01-08 03:58:06 -08:00
Marc Tamlyn
4df1172665
Fix reference to BasicAuthentication in settings.
2013-01-08 11:45:55 +00:00
Mark Aaron Shirley
a897eb5480
Create separate *NullableOneToOneTests TestCase
2013-01-07 16:27:31 -08:00
Tom Christie
4e8f55887d
Clean up test slightly. Refs #552
2013-01-07 21:37:44 +00:00
Tom Christie
31b585f26a
Note paginate_by=None usage. Fixes #555 .
2013-01-07 21:13:10 +00:00
Tom Christie
4bb504732d
Respect blank=True on relational fields. Fixes #537
2013-01-07 21:08:55 +00:00
Tom Christie
36fa722ebb
Merged to latest master
2013-01-07 21:04:52 +00:00
Tom Christie
e429f702e0
Fix PAGINATE_BY_PARAM docs. Refs #551
2013-01-07 20:17:52 +00:00
Tom Christie
d9df15f321
Added @juanriaza's djangorestframework-msgpack
package to the docs.
2013-01-07 17:36:31 +00:00
Tom Christie
de00d3720e
Added @mjtamlyn. Thanks!
2013-01-07 17:36:31 +00:00
Tom Christie
47f0d17f4d
Merge pull request #562 from mjtamlyn/view-name
...
Support URL namespaces.
2013-01-07 06:55:33 -08:00
Marc Tamlyn
5bded1ecf0
Use ResolveMatch.view_name so namespaces work.
2013-01-07 14:34:45 +00:00
Tom Christie
55584928ca
Merge pull request #561 from mjtamlyn/import-errors
...
When importing settings, don't suppress any old error which happens
2013-01-07 05:01:39 -08:00
Marc Tamlyn
c736b80290
Be more informative when reporting import errors.
2013-01-07 12:52:20 +00:00