mirror of
https://github.com/inventree/InvenTree.git
synced 2025-10-25 10:27:39 +00:00
optimize mro
This commit is contained in:
@@ -37,17 +37,12 @@ class OptionalFilterabelSerializer:
|
|||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
"""Initialize the serializer."""
|
"""Initialize the serializer."""
|
||||||
|
# Set filterable options for future ref
|
||||||
if self.is_filterable is None:
|
if self.is_filterable is None:
|
||||||
self.is_filterable = kwargs.pop('is_filterable', None)
|
self.is_filterable = kwargs.pop('is_filterable', None)
|
||||||
self.is_filterable_default = kwargs.pop('is_filterable_default', True)
|
self.is_filterable_default = kwargs.pop('is_filterable_default', True)
|
||||||
super().__init__(*args, **kwargs)
|
|
||||||
|
|
||||||
|
# remove filter args from kwargs
|
||||||
class FractionalFilterabelSerializer:
|
|
||||||
"""A."""
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
"""Add detail fields."""
|
|
||||||
kwargs = PathScopedMixin.gather_filters(self, kwargs)
|
kwargs = PathScopedMixin.gather_filters(self, kwargs)
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
PathScopedMixin.do_filtering(self, *args, **kwargs)
|
PathScopedMixin.do_filtering(self, *args, **kwargs)
|
||||||
@@ -67,7 +62,7 @@ class PathScopedMixin(serializers.Serializer):
|
|||||||
|
|
||||||
def gather_filters(self, kwargs):
|
def gather_filters(self, kwargs):
|
||||||
"""Gather filterable fields."""
|
"""Gather filterable fields."""
|
||||||
if getattr(self, '_was_filtered', False):
|
if getattr(self, '_was_filtered', False) or not hasattr(self, 'fields'):
|
||||||
return kwargs
|
return kwargs
|
||||||
self._was_filtered = True
|
self._was_filtered = True
|
||||||
|
|
||||||
@@ -299,9 +294,7 @@ class DependentField(serializers.Field):
|
|||||||
|
|
||||||
|
|
||||||
class InvenTreeModelSerializer(
|
class InvenTreeModelSerializer(
|
||||||
OptionalFilterabelSerializer,
|
OptionalFilterabelSerializer, serializers.ModelSerializer
|
||||||
FractionalFilterabelSerializer,
|
|
||||||
serializers.ModelSerializer,
|
|
||||||
):
|
):
|
||||||
"""Inherits the standard Django ModelSerializer class, but also ensures that the underlying model class data are checked on validation."""
|
"""Inherits the standard Django ModelSerializer class, but also ensures that the underlying model class data are checked on validation."""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user