Related Field class for representing external keys? #999
Unanswered
rlittlefield
asked this question in
Q&A
Replies: 1 comment 2 replies
-
This question seems to be related to #942 where we are discussing what is currently working and what not. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Has anyone had luck adapting one of the related field classes to take a single "something_id" field that is not defined as a foreign key in the database or model, and generate output that fits into the relationships object?
For example, if I have a Books model that has an author_id field, in which the Author model and related table don't exist. I still want to have a relationship property added for
"author": {"data": {"type": "users", "id": "1324"}}
.I didn't see an option for this in the docs, as they all seem to require an actual model. If that isn't available, my next option is to see if there is way to generate a fake model in django for objects that don't actually live in the db. If those don't work, I'll see about making a new
ExternalKeyRelatedField
that can do this.Update:
Subclassing
RelatedResourceField
not working so far. The superclass wants a model, as does the code inutils.py
inget_related_resource_type
. I don't think it is worth it to subclass the whole renderer.Any suggestions?
Beta Was this translation helpful? Give feedback.
All reactions