diff --git a/djangoldp/models.py b/djangoldp/models.py index 4b9e5a6a95b9471b9eacb177bc34d0e27e9b6688..edf293e79714b0015a73cd502b7e9a0a3a8a6e14 100644 --- a/djangoldp/models.py +++ b/djangoldp/models.py @@ -1,5 +1,8 @@ from django.conf import settings from django.db import models +from django.contrib.auth.models import User + +User._meta.serializer_fields = ('username','first_name','last_name') class LDPSource(models.Model): container = models.URLField() diff --git a/djangoldp/serializers.py b/djangoldp/serializers.py index 673bbb3e31d50fd776409f59af428edaf0d557ae..8e471d5e673bc2275e68214fa5248b2b0a76e336 100644 --- a/djangoldp/serializers.py +++ b/djangoldp/serializers.py @@ -81,7 +81,10 @@ class LDPSerializer(HyperlinkedModelSerializer): serializer_url_field = JsonLdIdentityField def get_default_field_names(self, declared_fields, model_info): - return super().get_default_field_names(declared_fields, model_info) + list(getattr(self.Meta, 'extra_fields', [])) + fields = super().get_default_field_names(declared_fields, model_info) + excludes = list(getattr(self.Meta, 'exclude', [])) + extra = list(getattr(self.Meta, 'extra_fields', [])) + return [f for f in fields if f not in excludes] + extra def to_representation(self, obj): data = super().to_representation(obj) @@ -95,8 +98,12 @@ class LDPSerializer(HyperlinkedModelSerializer): class Meta: model = relation_info.related_model depth = nested_depth - 1 - fields = '__all__' - + try: + fields = model._meta.serializer_fields + except: + fields = '__all__' + + return NestedLDPSerializer, get_nested_relation_kwargs(relation_info) @classmethod