I use the django comments from contrib and I have an object (entry) that has some comments associated with it. In my tastypie resources I have:
class CommentResource(ModelResource):
user = fields.ForeignKey(UserResource, 'user')
class Meta:
queryset = Comment.objects.all()
resource_name = 'comments'
allowed_methods = ['get']
fields = ['comment', 'resource_uri', 'submit_date', 'user',]
filtering = {
'user': ALL_WITH_RELATIONS,
}
and I can get all the comments, or filter them by user. It’s working ok.
Now I’m not sure, how would I do the same kind of filter but based on a certain entry object instead of user?
Thanks for your help.
Without knowing what is the relationship between the
entryandcommentit is hard to give a concrete answer but in a nut shell given that entry and comments are linked via manytomany relationship:fields.ToManyFieldto the EntryResource for CommentResource'comments' : ALL_WITH_RELATIONSto the filtering dict inEntryResourceAdditionally, you could add a nested resource or a custom URL to the Comment to filter them based on an entry, but it all depends on your design.
Almost verbatim example for the above is given in Tastypie docs here.