RESTful api for like / different

时间:2013-02-01 03:39:59

标签: django rest tastypie

我将like建模为数据库表

class UserLikeAlbumImage(models.Model):
    user = models.ForeignKey(User)
    album_image = models.ForeignKey(AlbumImage)
    created_at = models.DateTimeField(auto_now_add=True)

    class Meta:
        unique_together = ('user', 'album_image')

目前我有

API / V1 / userlikealbumimage /
api / v1 / userlikealbumimage / 3#3是UserLikeAlbumImage的id

我想要

/像/用户/ {用户ID} /影像/ {图像-ID} 来自The REST-way to check/uncheck like/unlike favorite/unfavorite a resource

特别是因为,将like视为(user,likes_object)的组合是很自然的。

/like/user/{user-id}/image/{image-id} 
GET: find out if user likes image
POST: `create` user likes image
DELETE: `delete` user likes image

/like/user/{user-id}/  
GET: list all images a user likes

/like/image/{image-id}/
GET: list all users who like this image

所以我假设这个寻址方案可以用django-tastypie表达,我该如何开始? (我应该搜索什么?)

---编辑---

好吧我通过

让它成功了
  def override_urls(self):
        return [
            url(r"^(?P<resource_name>%s)/user/(?P<user__id>\d+)/image/(?P<album_image__id>\d+)/$" % self._meta.resource_name,
                self.wrap_view('dispatch_detail'), name="api_dispatch_detail"),
            ]

现在的问题是,这是安静吗?

0 个答案:

没有答案