From b6df77f2801c6e597ffc9dcb1d663a70e9cb4933 Mon Sep 17 00:00:00 2001 From: Craig de Stigter Date: Tue, 19 Jan 2016 09:16:46 +1300 Subject: [PATCH] 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. --- rest_framework/fields.py | 10 ---------- rest_framework/relations.py | 4 ---- 2 files changed, 14 deletions(-) diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 8541bc43a..4911b365a 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -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 diff --git a/rest_framework/relations.py b/rest_framework/relations.py index 0bcdcdd95..083b56bf8 100644 --- a/rest_framework/relations.py +++ b/rest_framework/relations.py @@ -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)