Can't instantiate LDPSerializer without Meta args
The LDPSerializer
is not in fact an extension of Serializer
but of HyperlinkedModelSerializer
As such it is not possible to use it outside of this context, and without the full Meta
args, whilst in DRF it's common to produce serializers like so:
my_serializer = LDPSerializer(user, data=request.POST)
LDPSerializer
cannot be used in this way. It must be done like so:
meta_args = {'model': Invoice, 'depth': 2, 'fields': ("@id", "title", "batches", "date")}
meta_class = type('Meta', (), meta_args)
serializer_class = type(LDPSerializer)('InvoiceSerializer', (LDPSerializer,), {'Meta': meta_class})
serializer = serializer_class(data=invoice)
The current LDPSerializer
should be renamed LDPModelSerializer
, reflecting its relationship to the Rest Framework base class
Another class should be provided LDPSerializer
, which extends Serializer
. It should only be concerned with extending the LDPSerializer to allow a resource to be serialized in LDP format without all the "automatic-ness" in the LDPModelSerializer