Reputation: 287
My serializer, quite basic:
class TestSerializer(serializers.Serializer):
date_time = serializers.DateTimeField()
wanted to try out from shell but I get False
each time I try to check it for validation.
> import datetime
> s=TestSerializer({'date_time': datetime.datetime(year=2012,month=12,day=12)}
> s.data
{'date_time': datetime.datetime(2012, 12, 12, 0, 0)}
> s.is_valid()
False
> s.errors
{u'non_field_errors': [u'No input provided']}
Why is this? What is going on?
Upvotes: 9
Views: 7406
Reputation: 122516
I think you need to specify data explicitly:
s = TestSerializer(data={'date_time': datetime.datetime(year=2012,month=12,day=12)}
Otherwise it assumes that the first argument is a model instance but that's not the case here.
Upvotes: 8