Allow SeralizarSpecPlugins to also specify serialization_spec
pmg103 opened this issue · 1 comments
pmg103 commented
Sometimes a plugin may itself need to do some somewhat complicated prefetching which could most easily be expressed as a serialization_spec
. This should be an alternative to implementing modify_queryset()
:
class RemainingCreditCost(SerializationSpecPlugin):
serialization_spec = [
{'activity_product_version_items': [
# etc
]}
]
def get_value(self, instance):
# Use the prefetched values from the spec above (which will NOT appear in the output)
pmg103 commented
This would allow a simpler implemenation of the Requires()
plugin too:
class Requires(SerializationSpecPlugin):
def __init__(self, fields):
self.serialization_spec = fields
Or maybe these should be combined into one