You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a particular use case here: I have a denormalized table that contains one data type (let's call it 'pieces') that gets aggregated up to another model (let's call them 'pies').
Since I can't do anything with pies without having all of the pieces (technical requirement), I've decided to keep a table representing only the pieces and aggregate up to the pie level when pies are asked for.
I noticed this line in the renderer code:
('id', encoding.force_text(resource_instance.pk) if resource_instance else None),
It's in the method build_json_resource_obj
Since my dataset has many repeats of the pie IDs, I can't use it as a pk, BUT once I aggregate the table the Pie Viewset, it IS unique. Since it is not the actual pk on the model, however, I get the error 'dict' object has no attribute 'pk'.
The ideal situation would be that I can set the pie ID as the id in the JSON API representiation.
Is there a built-in way to handle this sort of use case?
The text was updated successfully, but these errors were encountered:
I am not 100% sure about your use case. But when using a ModelSerializer this is currently not possible: look at discussion #155 But you could also use a python model and overwrite pk property see discussion at #704
Closing this as duplicate. If you think it is not a duplicate please comment or otherwise continue the discussion in the other issue if needed. Thanks.
Hi there!
I have a particular use case here: I have a denormalized table that contains one data type (let's call it 'pieces') that gets aggregated up to another model (let's call them 'pies').
Since I can't do anything with pies without having all of the pieces (technical requirement), I've decided to keep a table representing only the pieces and aggregate up to the pie level when pies are asked for.
I noticed this line in the renderer code:
('id', encoding.force_text(resource_instance.pk) if resource_instance else None),
It's in the method
build_json_resource_obj
Since my dataset has many repeats of the pie IDs, I can't use it as a pk, BUT once I aggregate the table the Pie Viewset, it IS unique. Since it is not the actual pk on the model, however, I get the error
'dict' object has no attribute 'pk'
.The ideal situation would be that I can set the pie ID as the id in the JSON API representiation.
Is there a built-in way to handle this sort of use case?
The text was updated successfully, but these errors were encountered: