Tom Christie
685706ff2b
Merge pull request #584 from radiosilence/master
...
Adding timedelta support to JSONEncoder, and an example of how to add decode support to a serializer.
2013-01-15 05:25:24 -08:00
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
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
191135d7b0
Version 2.1.16
2013-01-14 09:20:44 +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
Juan Riaza
268f60999c
unused imports
2013-01-10 15:48:22 +01: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
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
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
Marc Tamlyn
5bded1ecf0
Use ResolveMatch.view_name so namespaces work.
2013-01-07 14:34:45 +00:00
Marc Tamlyn
c736b80290
Be more informative when reporting import errors.
2013-01-07 12:52:20 +00:00
Michael Mior
9b67a33b92
Use the correct static template tag in Django 1.5
2013-01-06 15:49:12 -05:00
Juan Riaza
a061e3d9e2
deprecate simplejson
2013-01-05 13:40:02 +01:00
Mark Aaron Shirley
213981cef3
Handle ObjectDoesNotExist exceptions when serializing null reverse one-to-one
2013-01-04 21:11:03 +01:00
Tom Christie
26f9acb45a
Validation errors instead of exceptions when serializers receive incorrect types. Fixes #402 .
2013-01-04 14:11:05 +00:00
Tom Christie
eb14278a3b
Add proper validation for updating relational fields with incorrect types. Fixes #446 .
2013-01-04 13:50:40 +00:00
Tom Christie
4c86fd46d7
Rename module for basic relational field tests
2013-01-04 13:05:31 +00:00
Tom Christie
6e9865cb71
Fix for #446 . Note: Also needs applying to other relational types.
2013-01-03 23:17:31 +00:00
Tom Christie
ad671022e1
Version 2.1.15
2013-01-03 22:14:11 +00:00
Tom Christie
7ed81c3c66
Tweak comment.
2013-01-03 22:06:55 +00:00
Tom Christie
6da21fa796
Merge pull request #541 from yprez/default_and_partial_serializers2
...
Fix "default" values and partial serializers. Fixes #532 .
2013-01-03 14:05:36 -08:00
Tom Christie
bfea7f64ee
Tweak behavior of hyperlinked fields that include an explicit format suffix.
2013-01-03 21:49:29 +00:00
Tom Christie
92ae08207a
Drop unused private save_m2m flag
2013-01-03 21:49:01 +00:00
Mark Aaron Shirley
8fd1f09dad
Move relation tests models into models.py
2013-01-03 10:23:13 +01:00
Yuri Prezument
3f5e938247
Some cleanup
2013-01-03 08:28:17 +02:00
Yuri Prezument
f2625fc38c
FileField validation - handle case when files=None, fixes #542
2013-01-02 22:12:26 +02:00
Yuri Prezument
1c8fccfdcd
Regression test for #542
2013-01-02 22:07:23 +02:00
Tom Christie
6da9cd5429
Add .patch()
method for RetrieveUpdateAPIView
2013-01-02 17:43:43 +00:00
Yuri Prezument
3873bc8a85
Add explaining comment
2013-01-02 15:57:00 +02:00
Yuri Prezument
6b962cfcf7
Fix "default" and partial serializers, fixes #532
2013-01-02 15:56:46 +02:00
Tom Christie
ef73160599
Added RetrieveUpdateAPIView
2013-01-02 13:46:19 +00:00
Tom Christie
b807f3d52a
Keep API backwards compatible.
2013-01-02 13:39:24 +00:00
Tom Christie
eff40391fb
Merge branch 'patch-support' of https://github.com/ahankinson/django-rest-framework into patch
2013-01-02 13:27:00 +00:00
Mark Aaron Shirley
44771e81b2
Update HyperlinkedForeignKeyTests to match PKForeignKeyTests
2013-01-01 17:51:39 +01:00
Andrew Hankinson
389ca3b3b1
Merge branch 'master' of git://github.com/tomchristie/django-rest-framework into patch-support
2013-01-01 11:36:23 -05:00
Mark Aaron Shirley
a617a3758f
Don't persist relation changes in ModelSerializer#restore_object()
2012-12-31 14:33:24 +01:00
Tom Christie
eff833b39d
Version 2.1.14
2012-12-31 08:53:49 +00:00
Tom Christie
8fad0a727a
Relation fields move into relations.py
2012-12-31 08:53:40 +00:00
Andrew Hankinson
c6f212238c
Merge branch 'master' of git://github.com/tomchristie/django-rest-framework into patch-support
2012-12-30 14:03:08 -04:00
Andrew Hankinson
df1880185c
Renaming DRFRequestFactory to RequestFactory
...
Updated tests to reflect the new name.
2012-12-30 13:58:08 -04:00
Andrew Hankinson
b9e48e8413
Removing Partial Update classes
...
PATCH methods merged into RetrieveUpdateDestroy class
2012-12-30 13:56:59 -04:00
Tom Christie
33580c82b3
Cleanup runtests/runcoverage
2012-12-30 08:06:11 +00:00
Sebastien Beal
b1e6b58c97
missing rest_framework templatetags for statics in login template
2012-12-30 13:24:05 +09:00
Tom Christie
12c4f1ecf7
Add reverse FK update tests
2012-12-29 18:26:47 +00:00
Tom Christie
18590a1568
Add test for hyperlinked reverse FK create. Refs #511
2012-12-29 18:17:48 +00:00
Tom Christie
0176fab475
Add TODO
2012-12-29 17:12:40 +00:00
Tom Christie
031a656667
Added hyperlinked FK create test
2012-12-29 17:12:07 +00:00
Tom Christie
caaf1c80f5
Support reverse FK creation
2012-12-29 16:51:41 +00:00
Tom Christie
51e2664491
Add FK create tests
2012-12-29 15:51:32 +00:00
Tom Christie
bf69205cd3
Tests for retrieving nullable relations
2012-12-29 13:33:03 +00:00
Tom Christie
809f5de330
Merge pull request #515 from yprez/blank_fields_issue
...
Fix for #514
2012-12-29 05:25:43 -08:00
Tom Christie
923f81d269
Nested serializers now support nullable relationships, plus test. Fixes #384
2012-12-29 13:19:05 +00:00
Tom Christie
250a7231d3
Add tests for nested FKs
2012-12-29 13:10:43 +00:00
Tom Christie
f7a82b6aee
Version 2.1.13
2012-12-28 12:45:05 +00:00
Tom Christie
acdb69be52
Include 'static' template tag to enable 1.3 compatible staticfiles behaviour
2012-12-28 12:36:28 +00:00
Tom Christie
3e4242fc43
django.contrib.staticfiles no longer needs to be in INSTALLED_APPS
2012-12-28 12:33:24 +00:00
Tom Christie
eefd5b05fb
Use compat import of urlpatterns
2012-12-27 20:20:01 +00:00
Tom Christie
24ed6dcfda
Update runtest settings to include staticfiles app.
2012-12-27 17:35:00 +00:00
Roman Akinfold
5ae7786930
Replace get_static_prefix templatetag with static
...
so now static files urls in html view are correct if we use cloud
storage to serve static files
2012-12-27 05:35:03 +08:00
Yuri Prezument
36e1987f59
Regression test for #532 - values overriden by "default" setting
2012-12-25 18:50:00 +02:00
Tom Christie
0576241b19
Merge pull request #523 from maspwr/related-required
...
RelatedField should respect self.required
2012-12-23 10:48:35 -08:00
Mark Aaron Shirley
f8a1256b1c
Update RelatedField#field_from_native coding style
2012-12-21 11:33:01 -08:00
Tom Christie
79aea2f0d0
Version 2.1.12
2012-12-21 09:18:35 +00:00
Tom Christie
04119245ec
Make nested tests consistent with pk and hyperlink tests
2012-12-21 09:15:28 +00:00
Tom Christie
37acea5240
Fix up test url model now filename has changed
2012-12-21 09:15:08 +00:00
Tom Christie
83feda6a69
Rename relationship tests so they show up together
2012-12-21 09:10:16 +00:00
Tom Christie
98919031db
Merge pull request #522 from maspwr/writable-serializers
...
Writable Serializers - READ tests
2012-12-21 01:05:37 -08:00
Mark Hughes
125f027d2d
Added setter to the auth property
2012-12-20 23:48:10 +00:00
Andrew Hankinson
e61eab43f4
Adjust PATCH test cases to use the new DRFRequestFactory
2012-12-20 00:28:01 -05:00
Andrew Hankinson
2b5deefe56
Subclass Django's RequestFactory to provide PATCH support
2012-12-20 00:27:29 -05:00
Mark Aaron Shirley
2f5582a1a6
Merge remote-tracking branch 'upstream/master' into related-required
2012-12-19 15:24:22 -08:00
Mark Aaron Shirley
ef475eb9bd
Merge remote-tracking branch 'upstream/master' into writable-serializers
2012-12-19 15:21:06 -08:00
Tom Christie
a493c83248
urls, patterns, include imports move to compat to support incoming 1.3 thru 1.6 import compatability
2012-12-19 23:12:27 +00:00
Tom Christie
46b313315a
Merge pull request #510 from joual/master
...
Fixes #509
2012-12-19 14:39:11 -08:00
Mark Aaron Shirley
ae6ca7456f
Merge remote-tracking branch 'upstream/master' into writable-serializers
2012-12-19 14:37:44 -08:00
Tom Christie
598ae3286a
Fix #521 . (Browseable API exception on delete)
2012-12-19 22:05:35 +00:00
Tom Christie
d90d5380d7
pep8
2012-12-19 22:05:00 +00:00
Mark Aaron Shirley
5c680c36e4
Check if RelatedField is required.
2012-12-19 09:26:40 -08:00
Yuri Prezument
c13f132a21
Failing test with partial serializer and foreign keys
2012-12-19 09:24:11 -08:00
Mark Aaron Shirley
c6a6d7ac15
remove all but the 'read' nested serializer tests
2012-12-19 07:33:49 -08:00
Trey Hunner
8a41d4aa54
Fix assertion for nested create test (missing id)
2012-12-19 07:30:19 -08:00
Trey Hunner
2910bfb527
Add two functions for more DRY reverse fk tests
2012-12-19 07:30:19 -08:00
Trey Hunner
cbf3429005
Add test for deleting a reverse fk relation
2012-12-19 07:30:19 -08:00
Trey Hunner
f92c5b28ad
Add test for creating a reverse fk relation
2012-12-19 07:30:19 -08:00
Trey Hunner
24e14b7d53
Add tests for retrieving/updating reverse fks
2012-12-19 07:30:18 -08:00
Tom Christie
ab86990ac8
HyperlinkedRealtedField tests. Refs #442 .
2012-12-18 19:20:31 +00:00
Tom Christie
6611514134
Whitespace
2012-12-18 19:20:10 +00:00
Tom Christie
6693d2d277
Fix for pks returning as strings when set in pre_save. Fixes #482 . Thanks to @n8agrin for the bug report.
2012-12-18 18:21:58 +00:00
Tom Christie
8f23b7f2f9
Version 2.1.11
2012-12-17 22:01:50 +00:00
Tom Christie
aa72f8d63d
Fix bug with M2M in browseable API
2012-12-17 21:59:51 +00:00
Yuri Prezument
c68f7ca580
blank=True fields are not required - fixes #514
2012-12-17 16:57:11 +02:00
Yuri Prezument
967f22e7d1
Failing test case for #514
...
Serializer errors are: {'title': [u'This field is required.']}
2012-12-17 16:50:20 +02:00