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

Question about included resources.#948

Unanswered
pasoulier asked this question inQ&A
Jun 1, 2021· 1 comments· 2 replies
Discussion options

When I'm querying a url that use several level of serializers (eg: /knight) I need to specify the included resources in the url otherwise I'm getting an error messageThis endpoint does not support the include parameter for path story. I'm only having this problem with the current version (4.2.0). I'm new using DRF and JSONAPI.

I'm made a simple app that you can see below.

Thanks for your help.

my models.py

fromdjango.dbimportmodels# Create your models here.classKnight(models.Model):name=models.CharField(max_length=50)nickname=models.CharField(max_length=50)classStory(models.Model):name=models.CharField(max_length=50)classQuest(models.Model):name=models.CharField(max_length=50)knights=models.ManyToManyField(Knight,related_name='quests')story=models.ForeignKey(Story,on_delete=models.CASCADE,related_name='quest')

urls.py

fromdjango.urlsimportpath,includefromrest_frameworkimportroutersfromrest_framework_json_apiimportserializersfromrest_framework_json_api.viewsimportModelViewSetfromrest_framework_json_api.relationsimportResourceRelatedFieldfrom .modelsimportKnight,Story,Questfrom .importviewsclassStorySerializer(serializers.ModelSerializer):quest=ResourceRelatedField(queryset=Quest.objects,many=True)included_serializers= {'quest':'knight.urls.QuestSerializer',    }classMeta:model=Storyfields= ('id','name','quest')classJSONAPIMeta:included_resources= ['quest']classQuestSerializer(serializers.ModelSerializer):story=ResourceRelatedField(queryset=Story.objects)included_serializers= {'story':'knight.urls.StorySerializer',    }classMeta:model=Questfields= ('id','name','story',)classJSONAPIMeta:included_resources= ['story']classKnightSerializer(serializers.ModelSerializer):quests=ResourceRelatedField(queryset=Quest.objects,many=True,    )included_serializers= {'quests':'knight.urls.QuestSerializer',    }classMeta:model=Knightfields= ('id','name','nickname','quests',)classJSONAPIMeta:included_resources= ['quests']classKnightViewSet(ModelViewSet):queryset=Knight.objects.all()serializer_class=KnightSerializerclassQuestViewSet(ModelViewSet):queryset=Quest.objects.all()serializer_class=QuestSerializerclassStoryViewSet(ModelViewSet):queryset=Story.objects.all()serializer_class=StorySerializerrouter=routers.DefaultRouter()router.register(r'/knights',KnightViewSet)router.register(r'/quests',QuestViewSet)router.register(r'/stories',StoryViewSet)urlpatterns= [path('',include(router.urls)),]
You must be logged in to vote

Replies: 1 comment 2 replies

Comment options

The change#900 in version 4.2.0 most likely causes this issue. The question is though whether there is an error in your setup (before#900 there was no validation done on included resources) or whether there is a regression in DJA itself.

When I look at your sample it looks fine to me. Is this a made up example or actual code you use?

At there is an example which we use in our test suite which passes.

Are you able to reproduce this issue with in the DJA example app? Or if it is easier you could also create a small example app yourself which reproduces the issue and post the repo here. Quick and dirty is fine as long as there is code which I can run on my machine easily to better discover the issue.

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

It's prettry close from the code that I'm using but not with "real" data.

Here for therepository

Thanks again for your time

@sliverc
Comment options

Thanks for the example repository. It is indeed a regression in DJA. I have create a bug report at#949

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
@pasoulier@sliverc

[8]ページ先頭

©2009-2025 Movatter.jp