diff --git a/djangoldp/serializers.py b/djangoldp/serializers.py index ef684a99069a2cb3cb7075d797a2140a4115daa7..6fbf308270ab301634cb26a77054d6b1c6927c4b 100644 --- a/djangoldp/serializers.py +++ b/djangoldp/serializers.py @@ -13,27 +13,31 @@ class ContainerSerializer(ListSerializer): def data(self): return ReturnDict(super(ListSerializer, self).data, serializer=self) -class JsonLdRelatedField(HyperlinkedRelatedField): +class JsonLdField(HyperlinkedRelatedField): def __init__(self, view_name=None, **kwargs): super().__init__(view_name, **kwargs) - #get the field name associated with the url of the view + self.get_lookup_args() + + def get_lookup_args(self): try: lookup_field = get_resolver().reverse_dict[self.view_name][0][0][1][0] self.lookup_field = lookup_field self.lookup_url_kwarg = lookup_field except MultiValueDictKeyError: pass + +class JsonLdRelatedField(JsonLdField): def to_representation(self, value): try: return {'@id': super().to_representation(value)} except ImproperlyConfigured: return value.pk -class JsonLdIdentityField(JsonLdRelatedField): +class JsonLdIdentityField(JsonLdField): def __init__(self, view_name=None, **kwargs): kwargs['read_only'] = True kwargs['source'] = '*' - super(JsonLdIdentityField, self).__init__(view_name, **kwargs) + super().__init__(view_name, **kwargs) def use_pk_only_optimization(self): return False diff --git a/setup.py b/setup.py index 4291b7732ad4cd751113599c4ec52cc8b3fb947d..a815cec25123e7ab94db151a0d92ad1ed106a473 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup setup( name='djangoldp', - version='0.4a1', + version='0.4a2', url='https://git.happy-dev.fr/happy-dev/djangoldp/', author="Startin'blox", author_email='sylvain@happy-dev.fr',