-
Notifications
You must be signed in to change notification settings - Fork 301
I can not assign an id "id": null #404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Use you own renderer to rewrite the JSONRenderer method: ('id', encoding.force_text(resource_instance.pk) if resource_instance else resource.get('id')) @classmethod
def build_json_resource_obj(cls, fields, resource, resource_instance, resource_name,
force_type_resolution=False):
# Determine type from the instance if the underlying model is polymorphic
if force_type_resolution:
resource_name = utils.get_resource_type_from_instance(resource_instance)
resource_data = [
('type', resource_name),
('id', encoding.force_text(resource_instance.pk) if resource_instance else resource.get('id')),
('attributes', cls.extract_attributes(fields, resource)),
]
relationships = cls.extract_relationships(fields, resource, resource_instance)
if relationships:
resource_data.append(('relationships', relationships))
# Add 'self' link if field is present and valid
if api_settings.URL_FIELD_NAME in resource and \
isinstance(fields[api_settings.URL_FIELD_NAME], relations.RelatedField):
resource_data.append(('links', {'self': resource[api_settings.URL_FIELD_NAME]}))
return OrderedDict(resource_data) |
There is already a discussion #155 on how support could be added to DJA. Closing this in favor of that issue. In your case you might also use a namedtuple though which has a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
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:
how could I get an id with a right value?
Thanks!
The text was updated successfully, but these errors were encountered: