Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Support custom model object keys #155

Closed
@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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /