Skip to content

I can not assign an id "id": null #404

Closed
@agalera

Description

@agalera

When doing a response with a dict, I have no way to return a different id, what can I do? I leave the code fragment and the answer I get

example_data = {
                "id": example.id,
                 .....
                "ref": example.ref,
                "error_url": self.data["attributes"]["error_url"],
                "return_url": self.data["attributes"]["return_url"],
            }
            
            serializer = self.get_serializer(data=example_data)
            serializer.is_valid(raise_exception=True)
            return Response(
                serializer.data,
                status=self.get_status_code(serializer.data),
                **kwargs
            )

We have trying to get one response from a new serializer whose content is the mix between two different models. We don't have a pk, because there are two models

The response returns this:

"data":{"type":"example","id":null,"attributes":{"...."}}

how could I get an id with a right value?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions