Skip to content

StringRelatedField() not working #1234

Answered by sliverc
Jer-Pha asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks for bringing this up. It seems that in DJA we have not covered the use case of StringRelatedField so that is the reason it is not working. Feel free to create an issue for this.

As a workaround though, what you can do is to create your own ResourceRelatedField and overwrite get_resource_id to return a string. You can use this field instead of StringRelatedField.

This could look like the following:

class StringResourceRelatedField(ResourceRelatedField):
    def get_resource_id(self, resource):
        return str(resource)

Using such a field would have the same effect as StringRelatedField but would of course only work with the DJA renderer.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Jer-Pha
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants