In dynamic usage with moderately complex serializer hierarchy, these are a real PITA.
* Why should I specify a queryset= kwarg on my RelatedField subclass when I have a get_queryset() method?
* When source=dynamic_thing(), don't make me check if it's equal to the field_name. Who cares? This also prevents calling bind() twice.
QueryParameterVersioning does not fall back to the value used in the `DEFAULT_VERSION` setting, while other versioning schemes do. This looks like a minor change, and incorporates the `self.default_version` set in the superclass.
I'll sheepishly admit that I edited this inline without running any tests or anything, so please let me know if this needs more work.
Previously an extra list wrapped nested validation errors raised from serializer's validate() methods.
That was inconsistent with the format of validation errors raised by validate_<fieldname> methods.
i.e. these two resulted in *different* behaviour:
def validate_foo(self):
raise ValidationError(['bar'])
def validate(self):
raise ValidationError({'foo': ['bar']})
Previously an extra list wrapped nested validation errors raised from serializer's validate() methods.
That was inconsistent with the format of validation errors raised by validate_<fieldname> methods.
i.e. these two resulted in *different* behaviour:
def validate_foo(self):
raise ValidationError(['bar'])
def validate(self):
raise ValidationError({'foo': ['bar']})
Otherwise if you want to subclass RelatedField in a read+write capacity you end up with this weird situation:
```
class MyField(serializers.RelatedField):
def __init__(self, **kwargs):
if not kwargs.get('read_only'):
kwargs.setdefault('queryset', MyModel.objects.all())
super(MyField, self).__init__(**kwargs)
```
This commit removes the check preventing you from just supplying the queryset anyway. Why shouldn't you?
These two tests were previously added in
7d79cf35b7
but we have now discovered that there are not actually two separate
cases, there was just a bug in the code that made it look that way.
This also removes a redundant check to see if `DecimalValidator` was
defined.
All the other code blocks in the Serialization tutorial can be copied and pasted, but there is one that includes the >>> shell prompt characters. This commit removes those characters, and also makes the output consistent with other code blocks by making it a comment.