Tastypie - 具有外国字段的多种形式的帖子

时间:2013-07-23 20:02:29

标签: django django-models multipartform-data tastypie

我正在尝试将多种形式发布到tastypie。

Django模型是:

class Message(models.Model):
    recipient = models.ForeignKey(User, null=True, related_name='recipient')

tastypie资源:

class MessageResource(MultipartResource, BaseResource):

    recipient = fields.ToOneField(UserResource, 'recipient',full=True)

表单数据的一部分:

POST /api/message/ HTTP/1.1
Host: 127.0.0.1:8286
Content-Type: multipart/form-data; boundary=Boundary+0xAbCdEfGbOuNdArY
Accept: application/json
Content-Length: 6462
Accept-Language: en;q=1, fr;q=0.9, de;q=0.8, ja;q=0.7, nl;q=0.6, it;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
User-Agent: C/1.0 (iPhone Simulator; iOS 6.1; Scale/1.00)

--Boundary+0xAbCdEfGbOuNdArY
Content-Disposition: form-data; name="fetched"

0
--Boundary+0xAbCdEfGbOuNdArY
Content-Disposition: form-data; name="recipient[id]"

2
--Boundary+0xAbCdEfGbOuNdArY
Content-Disposition: form-data; name="recipient[username]"

joe
--Boundary+0xAbCdEfGbOuNdArY
Content-Disposition: form-data; name="text"

test
--Boundary+0xAbCdEfGbOuNdArY
Content-Disposition: form-data; name="image"; filename="photo.png"
Content-Type: image/png

<binary data>

由于收件人是相关对象,因此其属性位于括号中。 tastypie无法识别这是一个相关对象而POST失败。

我错过了什么?

0 个答案:

没有答案