You can use SerializerMethodField
and write custom method for this.
class AlbumSerializer(HyperlinkedModelSerializer):
song_set = serializers.SerializerMethodField()
class Meta:
model = Album
fields = [
'pk',
'timestamp',
'song_set'
]
def get_song_set(self, instance):
songs = instance.song_set.all().order_by('-timestamp')
return SongListSerializer(songs, many=True).data
Related Contents:
- Django REST Framework POST nested objects
- Pass extra arguments to Serializer Class in Django Rest Framework
- Django REST Framework – Separate permissions per methods
- How do I create a login API using Django Rest Framework?
- django-rest-framework 3.0 create or update in nested serializer
- How to return custom JSON in Django REST Framework
- Django REST Framework serializer field required=false
- Creating a JSON response using Django and Python
- NumPy array is not JSON serializable
- What’s the best way to parse a JSON response from the requests library?
- How can I enable CORS on Django REST Framework
- Disable a method in a ViewSet, django-rest-framework
- is not JSON serializable
- Django Rest Framework – Could not resolve URL for hyperlinked relationship using view name “user-detail”
- Django Rest Framework – Authentication credentials were not provided
- Include intermediary (through model) in responses in Django Rest Framework
- Retrieving a Foreign Key value with django-rest-framework serializers
- Django rest framework serializing many to many field
- Django Rest Framework — no module named rest_framework
- Python/Django: how to assert that unit test result contains a certain string?
- How do I return JSON without using a template in Django?
- What is the benefit of using a HyperlinkedModelSerializer in DRF?
- How do I get JSON data from RESTful service using Python?
- Cannot apply DjangoModelPermissions on a view that does not have `.queryset` property or overrides the `.get_queryset()` method
- Return the current user with Django Rest Framework
- OperationalError, no such column. Django
- Django Rest Framework and JSONField
- Django serializer Imagefield to get full URL
- How can I register a single view (not a viewset) on my router?
- Proper way to consume data from RESTFUL API in django
- Order of Serializer Validation in Django REST Framework
- Get current user in Model Serializer
- Django Rest Framework – APIView Pagination
- User Authentication in Django Rest Framework + Angular.js web app
- Serializing list to JSON [duplicate]
- Django Rest Framework POST Update if existing or create
- Django Rest Framework – Get related model field in serializer
- is not JSON serializable
- Django Test Client Method Override Header
- how to reverse the URL of a ViewSet’s custom action in django restframework
- Why does Django Rest Framework discourage model level validation?
- Bad Django / uwsgi performance
- Django Python rest framework, No ‘Access-Control-Allow-Origin’ header is present on the requested resource in chrome, works in firefox
- how to add annotate data in django-rest-framework queryset responses?
- Adding REST to Django [closed]
- Django Serializer Method Field
- Using Django Rest Framework, how can I upload a file AND send a JSON payload?
- How to display all model fields with ModelSerializer?
- How to serialize Django queryset.values() into json?
- Django viewset has not attribute ‘get_extra_actions’