Open
Description
Filtering across relationships currently uses the default queryset. For example:
class ArticleFilter(FilterSet):
is_published = filers.BooleanFilter()
body = filter.CharFilter()
class AuthorFilter(FilterSet):
article = filters.RelatedFilter(ArticleFilter)
class AuthorViewSet(viewsets.ModelViewSet):
queryset = models.Author.objects.all()
filter_class = AuthorFilter
class PostViewSet(viewsets.ModelViewSet):
queryset = models.Post.objects.all()
filter_class = PostFilter
def get_queryset(self):
qs = super(PostViewSet, self).get_queryset()
user = self.request.user
# get user's posts and published posts
user_posts = qs.filter(author__user=user)
published_posts = qs.filter(is_published=True)
return user_posts | published_posts
While you're not able to view unpublished posts of other authors, you are able to filter across the relationship and derive that an author may be preparing an article about some topic.
eg:
/api/authors?post__is_published=false&post__body__contains=juicy%20story%20details
Metadata
Metadata
Assignees
Labels
No labels