Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Related Field class for representing external keys?#999

Unanswered
rlittlefield asked this question inQ&A
Discussion options

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 newExternalKeyRelatedField that can do this.

Update:
SubclassingRelatedResourceField 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?

You must be logged in to vote

Replies: 1 comment 2 replies

Comment options

This question seems to be related to#942 where we are discussing what is currently working and what not.

You must be logged in to vote
2 replies
@rlittlefield
Comment options

This might be a bit different because this is just a TextField not a GenericForeignKey. I already know the type, but the type doesn't actually have a table or model object anywhere.

@sliverc
Comment options

OK I see your point. This is certainly not gonna be easy and most likely you will need to have a custom json renderer class overwritingextract_relationships.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@rlittlefield@sliverc

[8]ページ先頭

©2009-2025 Movatter.jp