I think SerializerMethodField
is what you’re looking for:
class FooSerializer(serializers.ModelSerializer):
my_field = serializers.SerializerMethodField('is_named_bar')
def is_named_bar(self, foo):
return foo.name == "bar"
class Meta:
model = Foo
fields = ('id', 'name', 'my_field')
http://www.django-rest-framework.org/api-guide/fields/#serializermethodfield
Related Contents:
- Django REST framework: non-model serializer
- What are the differences between django-tastypie and djangorestframework? [closed]
- Token Authentication for RESTful API: should the token be periodically changed?
- Django Rest Framework: Disable field update after object is created
- Django testing rest-framework: APIRequestFactory vs APIClient
- How to get Request.User in Django-Rest-Framework serializer?
- Django Rest Framework remove csrf
- How to change field name in Django REST Framework
- Django: TemplateDoesNotExist (rest_framework/api.html)
- Django REST Framework custom fields validation
- Django Rest Framework with ChoiceField
- Django rest framework nested self-referential objects
- How do you filter a nested serializer in Django Rest Framework?
- Write only, read only fields in django rest framework
- RuntimeError: Model class django.contrib.sites.models.Site doesn’t declare an explicit app_label and isn’t in an application in INSTALLED_APPS
- Pass extra arguments to Serializer Class in Django Rest Framework
- Pass request context to serializer from Viewset in Django Rest Framework
- Django REST framework serializer without a model
- Aggregate (and other annotated) fields in Django Rest Framework serializers
- How to set current user to user field in Django Rest Framework?
- How Can I Disable Authentication in Django REST Framework
- Authorization Credentials Stripped — django, elastic beanstalk, oauth
- How do I create a login API using Django Rest Framework?
- Django test RequestFactory vs Client
- Django Rest framework, how to include ‘__all__’ fields and a related field in ModelSerializer ?
- Django REST Framework combining routers from different apps
- Capture parameters in django-rest-framework
- Django Rest Framework, passing parameters with GET request, classed based views
- generics vs viewset in django rest framework, how to prefer which one to use?
- SocketException: OS Error: Connection refused, errno = 111 in flutter using django backend
- Additional field while serializing django rest framework
- How to make a PATCH request using DJANGO REST framework
- Django – Where are the params stored on a PUT/DELETE request?
- Is it possible to use FastAPI with Django?
- How can I test binary file uploading with django-rest-framework’s test client?
- Django : DRF Token based Authentication VS JSON Web Token
- Serializing a list of objects with django-rest-framework
- Exclude a field from django rest framework serializer
- How to programmatically call a Django Rest Framework view within another view?
- What are the best practices to use AngularJS with Django [closed]
- Django REST Framework viewset per-action permissions
- Django and Restful APIs
- context in nested serializers django rest framework
- Django rest framework – filtering for serializer field
- 405 POST method not allowed
- Turn off automatic pagination of Django Rest Framework ModelViewSet
- Is APITest with Query params different then just normal url?
- How to make a POST simple JSON using Django REST Framework? CSRF token missing or incorrect
- Django: Rest Framework authenticate header
- Difference between APIView class and viewsets class?