0

我正在尝试向美味派发布多种形式。

Django 模型是:

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

美味派资源:

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>

由于接收者是一个相关的对象,它的属性在括号中。美味派不承认这是一个相关的对象,并且 POST 失败。

我错过了什么?

4

0 回答 0