RESTful api for similar / dissimilar
I have modeled like
as DB table
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')
currently I have
api / v1 / userlikealbumimage /
api / v1 / userlikealbumimage / 3 # 3 - UserLikeAlbumImage id
I want to have
/ as / user / {user id} / {image / image-id} from REST-way to check / uncheck / versus favorite / unusable resource
Moreover, it is natural to think like
as a composition (user, loved_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
So my guess is that this addressing scheme can be expressed with django-tastypie, how do I get started? (what should I be looking for?)
--- EDIT ---
ok I did it with
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"),
]
The question is, is it calm?
+3
source to share
No one has answered this question yet
See similar questions:
or similar: