from rest_framework import serializers from django.db import models class Bar(models.Model): id = models.IntegerField() class Meta: app_label = 'test'
class Foo(models.Model): bar = models.ForeignKey( Bar, on_delete=models.PROTECT, ) class Meta: app_label = 'test' class FooSerializer(serializers.ModelSerializer): class Meta: model = Foo fields = ( 'bar', ) extra_kwargs = { 'bar': { 'source': 'bar.id' } } I copied this from DRF_Github_issues <https://github.com/encode/django-rest-framework/issues/7368> . the source in the extra_kwargs doesn't work more than one depth relation (bar.id) , but works with one (bar) . if I defined the field in the serializer class , I'll have to redefine the validators of the model as well , what's the best workaround without redefining the validators . -- You received this message because you are subscribed to the Google Groups "Django REST framework" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-framework+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/1b98a373-4339-4229-9101-dedbf9c72dbcn%40googlegroups.com.