class AccountSerializer(serializers.ModelSerializer): other_name = serializers.CharField(source='name', read_only=True) other_field = serializers.SerializerMethodField() class Meta: model = Account fields = ('id', 'account_name', 'users', 'created') fields = '__all__' exclude = ('users',) depth = 1 read_only_fields = ('account_name',) def get_other_field(self, obj): return obj.dept.name if obj.dept else ''
|