mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-08 06:14:47 +03:00
Remove the two most irritating style warnings that I keep banging my head against.
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.
This commit is contained in:
parent
8f108e8bcf
commit
b6df77f280
|
@ -322,16 +322,6 @@ class Field(object):
|
|||
Called when a field is added to the parent serializer instance.
|
||||
"""
|
||||
|
||||
# In order to enforce a consistent style, we error if a redundant
|
||||
# 'source' argument has been used. For example:
|
||||
# my_field = serializer.CharField(source='my_field')
|
||||
assert self.source != field_name, (
|
||||
"It is redundant to specify `source='%s'` on field '%s' in "
|
||||
"serializer '%s', because it is the same as the field name. "
|
||||
"Remove the `source` keyword argument." %
|
||||
(field_name, self.__class__.__name__, parent.__class__.__name__)
|
||||
)
|
||||
|
||||
self.field_name = field_name
|
||||
self.parent = parent
|
||||
|
||||
|
|
|
@ -65,10 +65,6 @@ class RelatedField(Field):
|
|||
self.queryset = kwargs.pop('queryset', self.queryset)
|
||||
self.html_cutoff = kwargs.pop('html_cutoff', self.html_cutoff)
|
||||
self.html_cutoff_text = kwargs.pop('html_cutoff_text', self.html_cutoff_text)
|
||||
assert self.queryset is not None or kwargs.get('read_only', None), (
|
||||
'Relational field must provide a `queryset` argument, '
|
||||
'or set 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