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

dynamically switch between ResourceRelatedField and HyperlinkedRelatedField #1038

Unanswered
jokiefer asked this question in Q&A
Discussion options

Default Scenario

class WebMapServiceSerializer(ModelSerializer):
 layers = HyperlinkedRelatedField(
 queryset=Layer.objects,
 many=True, # necessary for M2M fields & reverse FK fields
 related_link_view_name='registry:wms-layers-list',
 related_link_url_kwarg='parent_lookup_service',
 self_link_view_name='registry:wms-relationships',
 )
 included_serializers = {
 'layers': LayerSerializer,
 }

If the request is without include=layers a simple HyperlinkedRelatedField shall be used.

Include Scenario

If the request is with include=layers parameter, the request will crash cause the HyperlinkedRelatedField drops the data.

So, IF and only IF the include for layers is needed i need to switch the field class for only this attribute to the ResourceRelatedField`to that the data is rendered.

Is there any way to do that simple?

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /