8
我要建一个Django tastypie API,而我在ManyToMany
关系Tastypie,在许多添加元素一对多的关系
例, models.py问题
class Picture(models.db):
""" A picture of people"""
people = models.ManyToManyField(Person, related_name='pictures',
help_text="The people in this picture",
)
class Person(models.db):
""" A model to represet a person """
name = models.CharField(max_length=200,
help_text="The name of this person",
)
资源:
class PictureResource(ModelResource):
""" API Resource for the Picture model """
people = fields.ToManyField(PersonResource, 'people', null=True,
related_name="pictures", help_text="The people in this picture",
)
class PersonResource(ModelResource):
""" API Resource for the Person model """
pictures = fields.ToManyField(PictureResource, 'pictures', null=True,
related_name="people", help_text="The pictures were this person appears",
)
我的问题是,我想有一个add_person
终点在我的图片资源。 如果我使用PUT
,那么我需要指定图片中的所有数据。 如果我使用PATCH
,我仍然需要指定图片中的所有人。 当然,我可以简单地生成网址,在那里我可以处理我的问题。问题在于它感觉不干净。
另一种解决方案是产生/api/picture/:id/people
终点,在那里我可以做GET
,POST
,PUT
,就像是一个新的资源,但我不知道如何实现这一点,我觉得奇怪,创造新的人在这个资源下。
有什么想法?
我莫名其妙地问我搜索我的问题同样的问题http://stackoverflow.com/questions/8613522/how-to-put-product-to-cart-via-tasytpie-api – seb 2012-04-12 00:51:24
对不起@seb我没有发现你的问题。如果您愿意,我可以删除我的问题,但请更改您的名称,因为“如何通过tasytpie API将产品放入购物车?”太具体了 – 2012-04-12 11:15:38
@seb - 你的问题仍然存在,我没有看到你接受了答案! – Mutant 2012-11-29 05:03:51