I have this code:
#api model class VideoResource(ModelResource): class Meta: queryset = Video.objects.all() include_resource_uri = False resource_name = 'video' authorization = DjangoAuthorization() class QuestionResource(ModelResource): user = fields.ToOneField(UserResource,'user',full=True) video = fields.ForeignKey(VideoResource,'video',full=True) class Meta: queryset = Question.objects.all() resource_name = 'question' include_resource_uri = False authorization = DjangoAuthorization() def obj_create(self, bundle, request=None, **kwargs): import json temp = json.loads(request.body, object_hook=_decode_dict) video = Video.objects.get(pk=temp['video']) return super(QuestionResource, self).obj_create(bundle, request, user=request.user, video=video)
The problem is that I get this error when sending this object:
{"video":21,"text":"sadasds"}
In the "video" field, data was provided that were not a URI, not a dictionary and does not have the attribute "pk": 21.
If I comment on this line:
video = fields.ForeignKey(VideoResource,'video',full=True)
Everything works fine, but then I can not get this information (video) when requesting /api/v1/questions/
My question is:
Perhaps your eyes can help me find a mistake :) Thank you!
Mc-
source share