- Notifications
You must be signed in to change notification settings - Fork302
-
Hi, I'm currently working on a project using django-rest-framework-json-api, and I have a use case where I need to include an extra attribute within the data objects in a relationship. Here’s an example of what I'm trying to achieve:
I'm looking to add a level field for each supplier within the relationships section. However, from what I understand, JSON Here's how I am currently resolving this with my serializers:
I was wondering if anyone else has encountered a similar requirement and how you approached it. Are there any workarounds or best practices to include additional attributes like level within relationships, while still adhering to the JSON Thanks. |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 2 comments 1 reply
-
Thinking about it I guess you have two options.
|
BetaWas this translation helpful?Give feedback.
All reactions
-
I appreciate the suggestion, but my question isn't about adding additional attributes in the data rendering phase (GET requests). I'm specifically looking to handle extra fields like level during POST or PATCH operations. For example, when submitting data for creation or updates, I want to include additional attributes in the relationships object |
BetaWas this translation helpful?Give feedback.
All reactions
-
My first suggestion also works on writing operations, in fact not just on the relationships key itself but on each relationship field you can have a You can see this in the JSON:API spec where it shows thatrelationships is a list ofresource identifier objects and there it states that a meta key is allowed. In your case this could look like this: "relationships": {"responsible_supplier": {"data": [{"type":"supplier","id":"c00f7b66-6768-4b42-b72e-bf2b018210c5","meta": {"level":1} }, {"type":"supplier","id":"8999d741-29ed-4d07-b228-7aa79b43d9a7","meta": {"level":2} }] }} I haven't used this before but to parse something like this you would need to implement your custom |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1