Skip to content

Commit 62113a7

Browse files
Fix get_default_valid_fields of OrderingFilter
1 parent a163c51 commit 62113a7

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

rest_framework/filters.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,17 @@ def get_default_valid_fields(self, queryset, view, context={}):
226226
)
227227
raise ImproperlyConfigured(msg % self.__class__.__name__)
228228

229+
model_field_names = [field.name for field in queryset.model._meta.fields]
230+
229231
return [
230232
(field.source.replace('.', '__') or field_name, field.label)
231233
for field_name, field in serializer_class(context=context).fields.items()
232-
if not getattr(field, 'write_only', False) and not field.source == '*'
234+
if (
235+
not getattr(field, 'write_only', False) and
236+
not field.source == '*' and (
237+
field_name in model_field_names or field.source in model_field_names
238+
)
239+
)
233240
]
234241

235242
def get_valid_fields(self, queryset, view, context={}):

0 commit comments

Comments
 (0)