-
Notifications
You must be signed in to change notification settings - Fork 298
Closed
Labels
@orf
Description
Hey, thanks for your work on this project. I was investigating integrating it with our EmberJS app but I ran into an issue. We have an Employee
model that has a normal integer primary key, but also a username
attribute. I'd like to only expose the username
as the primary key, using DRF this is simple:
class EmployeeSerializer(serializers.ModelSerializer): id = serializers.ReadOnlyField(source="user.username") ...
However in build_json_resource_obj
it just uses instance.pk:
def build_json_resource_obj(fields, resource, resource_instance, resource_name): resource_data = [ ('type', resource_name), ('id', encoding.force_text(resource_instance.pk) if resource_instance else None), ...
Can you use the serializers ID field if available, and fallback to the instances PK?