mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-08 06:14:47 +03:00
Fix overzealous RelatedField queryset validation.
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?
This commit is contained in:
parent
552707381e
commit
69dfb5d818
|
@ -69,10 +69,6 @@ class RelatedField(Field):
|
|||
'Relational field must provide a `queryset` argument, '
|
||||
'or set read_only=`True`.'
|
||||
)
|
||||
assert not (self.queryset is not None and kwargs.get('read_only', None)), (
|
||||
'Relational fields should not provide a `queryset` argument, '
|
||||
'when setting read_only=`True`.'
|
||||
)
|
||||
kwargs.pop('many', None)
|
||||
kwargs.pop('allow_empty', None)
|
||||
super(RelatedField, self).__init__(**kwargs)
|
||||
|
|
Loading…
Reference in New Issue
Block a user