dci-python-backend-assignments / tdd-class-social

6 stars 4 forks source link

As a user I want to be able to filter posts by role. #59

Open mathiasbrito-dci opened 2 years ago

mathiasbrito-dci commented 2 years ago

As a user, I must be able to retrieve a list of posts filtered by the creator's role. e.g., by teacher, by student, by researcher, etc.

lamalul commented 2 years ago

@mathiasbrito-dci @divyaChandran10 the role attribute has been deleted. Is the issue still relevant? we added a method to filter by creator_username, would it be alternative?

class PostViewSet(ModelViewSet):
    queryset = Post.objects.all()
    serializer_class = PostSerializer

    def get_queryset(self):
        search_term = self.request.query_params.get('search_terms')
        if search_term:
            queryset = Post.objects.filter(creator__username__icontains=search_term)
        else:
            queryset = Post.objects.all()
        return queryset
lamalul commented 2 years ago

@mathiasbrito-dci shall we add an extra SearchView or is it enough to do the search in the localhost:8000/posts/?search_terms=username ? e.g. http://127.0.0.1:8000/posts/?search_terms=La

mathiasbrito-dci commented 2 years ago

@mathiasbrito-dci @divyaChandran10 the role attribute has been deleted. Is the issue still relevant? we added a method to filter by creator_username, would it be alternative?

we need to think about it, I think we can find a solution without the need of having the role, for example, thinking real quick here, if we want to limit the search by student we can just search on the student table.

divyaChandran10 commented 2 years ago

I think, People in general will search any post by title regardless of the role.

lamalul commented 2 years ago

@mathiasbrito-dci @divyaChandran10 the role attribute has been deleted. Is the issue still relevant? we added a method to filter by creator_username, would it be alternative?

we need to think about it, I think we can find a solution without the need of having the role, for example, thinking real quick here, if we want to limit the search by student we can just search on the student table.

You mean we make new models for StudentPost, TeacherPost, InsitutionPost?

lamalul commented 2 years ago

I think, People in general will search any post by title regardless of the role.

The Issue is about viewing Students/Teacher/Institution posts by just clicking on some filter button. or a link .

divyaChandran10 commented 2 years ago

Yes I understood that, but since the role attribute is removed from models, can we do the common search of posts. If yes, we can change the issue as 'Search the posts by Title'.