mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-29 17:39:48 +03:00
Filter model properties in get_default_valid_fields of OrderingFilter
This commit is contained in:
parent
62113a794a
commit
c7f8b1456a
|
@ -226,16 +226,19 @@ class OrderingFilter(BaseFilterBackend):
|
||||||
)
|
)
|
||||||
raise ImproperlyConfigured(msg % self.__class__.__name__)
|
raise ImproperlyConfigured(msg % self.__class__.__name__)
|
||||||
|
|
||||||
model_field_names = [field.name for field in queryset.model._meta.fields]
|
model_class = queryset.model
|
||||||
|
model_property_names = [
|
||||||
|
# 'pk' is a property added in Django's Model class, however it is valid for ordering.
|
||||||
|
attr for attr in dir(model_class) if isinstance(getattr(model_class, attr), property) and attr != 'pk'
|
||||||
|
]
|
||||||
|
|
||||||
return [
|
return [
|
||||||
(field.source.replace('.', '__') or field_name, field.label)
|
(field.source.replace('.', '__') or field_name, field.label)
|
||||||
for field_name, field in serializer_class(context=context).fields.items()
|
for field_name, field in serializer_class(context=context).fields.items()
|
||||||
if (
|
if (
|
||||||
not getattr(field, 'write_only', False) and
|
not getattr(field, 'write_only', False) and
|
||||||
not field.source == '*' and (
|
not field.source == '*' and
|
||||||
field_name in model_field_names or field.source in model_field_names
|
field.source not in model_property_names
|
||||||
)
|
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user