<feed xmlns='http://www.w3.org/2005/Atom'>
<title>django-rest-framework/rest_framework/utils, branch 2.1.17</title>
<subtitle>Web APIs for Django.</subtitle>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/fork/django-rest-framework/'/>
<entry>
<title>Add timedelta encoder to the JSONEncoder class.</title>
<updated>2013-01-15T13:08:52+00:00</updated>
<author>
<name>James Cleveland</name>
</author>
<published>2013-01-15T13:02:53+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/fork/django-rest-framework/commit/?id=4fc3b1ba56239a1fb999f9aef99cdbcfbc9aa254'/>
<id>4fc3b1ba56239a1fb999f9aef99cdbcfbc9aa254</id>
<content type='text'>
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()
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
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()
</pre>
</div>
</content>
</entry>
<entry>
<title>deprecate simplejson</title>
<updated>2013-01-05T12:40:02+00:00</updated>
<author>
<name>Juan Riaza</name>
</author>
<published>2013-01-05T12:40:02+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/fork/django-rest-framework/commit/?id=a061e3d9e20c4c481c2ac2eee5b17bb1430cace6'/>
<id>a061e3d9e20c4c481c2ac2eee5b17bb1430cace6</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Make filtering optional, and pluggable.</title>
<updated>2012-11-07T21:07:24+00:00</updated>
<author>
<name>Tom Christie</name>
</author>
<published>2012-11-07T21:07:24+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/fork/django-rest-framework/commit/?id=47b534a13e42d498629bf9522225633122c563d5'/>
<id>47b534a13e42d498629bf9522225633122c563d5</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Fix repeated breadcrumbs when optional trailing slash is used</title>
<updated>2012-11-07T10:03:51+00:00</updated>
<author>
<name>Tom Christie</name>
</author>
<published>2012-11-07T10:03:51+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/fork/django-rest-framework/commit/?id=296b737fb6f8bca21272a9c3bcfdfcd5ce6a50fc'/>
<id>296b737fb6f8bca21272a9c3bcfdfcd5ce6a50fc</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Tweak parsers to take parser_context</title>
<updated>2012-10-15T12:27:50+00:00</updated>
<author>
<name>Tom Christie</name>
</author>
<published>2012-10-15T12:27:50+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/fork/django-rest-framework/commit/?id=9c1fba3483b7e81da0744464dcf23a5f12711de2'/>
<id>9c1fba3483b7e81da0744464dcf23a5f12711de2</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Fix yaml rendering</title>
<updated>2012-10-10T15:34:00+00:00</updated>
<author>
<name>Tom Christie</name>
</author>
<published>2012-10-10T15:34:00+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/fork/django-rest-framework/commit/?id=d905d1cbd3a20191835be1a5bddee0aabf136ec6'/>
<id>d905d1cbd3a20191835be1a5bddee0aabf136ec6</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Change package name: djangorestframework -&gt; rest_framework</title>
<updated>2012-09-20T12:06:27+00:00</updated>
<author>
<name>Tom Christie</name>
</author>
<published>2012-09-20T12:06:27+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/fork/django-rest-framework/commit/?id=4b691c402707775c3048a90531024f3bc5be6f91'/>
<id>4b691c402707775c3048a90531024f3bc5be6f91</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
</feed>
