Skip to content

Instantly share code, notes, and snippets.

@JockeTF
Created January 8, 2015 13:06
Show Gist options
  • Save JockeTF/b48b3385eaa7098eb3f5 to your computer and use it in GitHub Desktop.
Save JockeTF/b48b3385eaa7098eb3f5 to your computer and use it in GitHub Desktop.
class UserFilter(ChainedFilterSet):
username = AllLookupsFilter()
full_name = AllLookupsFilter()
created_at = AllLookupsFilter()
class Meta():
model = get_user_model()
fields = ('id', 'username', 'full_name', 'created_at')
class PostFilter(ChainedFilterSet):
content = AllLookupsFilter()
user = RelatedFilter('api.filters.UserFilter')
created_at = AllLookupsFilter()
updated_at = AllLookupsFilter()
class Meta():
model = Post
fields = ('id', 'content', 'user_id', 'user', 'created_at', 'updated_at')
class CommentFilter(ChainedFilterSet):
post = RelatedFilter('api.filters.PostFilter')
user = RelatedFilter('api.filters.UserFilter')
content = AllLookupsFilter()
created_at = AllLookupsFilter()
class Meta():
model = Comment
fields = ('id', 'post_id', 'post', 'user_id', 'user', 'content', 'created_at')
class CommentViewSet(ModelViewSet):
queryset = Comment.objects.all()
serializer_class = CommentSerializer
filter_class = CommentFilter
ordering_fields = ('id', 'created_at', 'updated_at')
search_fields = ('content',)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment