Skip to content

✨ Add Advanced Filtering and Search to Task API #1

Description

@mohammad-hussein-dev

πŸš€ Task: Add Advanced Filtering and Search to Task API

πŸ“Œ Goal

Enhance the Task API to support advanced filtering (by status, priority, category, date) and search (by title and description) using django-filter.


🧩 Why This Matters

  • Makes the API more powerful and user-friendly.
  • Reduces frontend processing by moving filtering logic to the backend.
  • Follows REST API best practices.

🧩 Subtasks

  • Add django-filter to requirements.txt
  • Create api/filters.py with TaskFilter class
  • Integrate filter into TaskListView (using FilterSet)
  • Add search functionality using SearchFilter (search in title and description)
  • Add ordering support (by created_at, deadline, priority)
  • Write unit tests for all filtering, search, and ordering scenarios
  • Update API documentation in README (or Swagger)

βœ… Acceptance Criteria

  • API supports filtering by status, priority, category, created_at, deadline
  • API supports search by title and description
  • API supports ordering by created_at, deadline, priority
  • All new features are covered by unit tests
  • API documentation is updated
  • No existing functionality is broken

πŸ§ͺ Testing Checklist

  • Test filtering by status (exact match)
  • Test filtering by priority (numeric)
  • Test filtering by category (case-insensitive)
  • Test filtering by created_at (date range)
  • Test filtering by deadline (date range)
  • Test search by title (partial match)
  • Test search by description (partial match)
  • Test ordering by created_at
  • Test ordering by deadline
  • Test ordering by priority
  • Test combined filters (status + priority + search)
  • Test empty results (no matching tasks)

πŸ“š Resources


βœ… Example Implementation (for reference)

# api/filters.py
import django_filters
from tasks.models import Task

class TaskFilter(django_filters.FilterSet):
    status = django_filters.CharFilter(lookup_expr='iexact')
    priority = django_filters.NumberFilter()
    category = django_filters.CharFilter(field_name='category__name', lookup_expr='iexact')
    created_at = django_filters.DateFromToRangeFilter()
    deadline = django_filters.DateFromToRangeFilter()

    class Meta:
        model = Task
        fields = ['status', 'priority', 'category', 'created_at', 'deadline']
# api/views.py
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.filters import SearchFilter, OrderingFilter

class TaskListView(generics.ListCreateAPIView):
    queryset = Task.objects.all()
    serializer_class = TaskSerializer
    filter_backends = [DjangoFilterBackend, SearchFilter, OrderingFilter]
    filterset_class = TaskFilter
    search_fields = ['title', 'description']
    ordering_fields = ['created_at', 'deadline', 'priority']

πŸ—“οΈ Deadline

No rush β€” take your time and focus on quality.

πŸ’¬ Questions?

Feel free to ask anytime. I'm here to help.


🏷️ Labels

good first issue, enhancement, help wanted

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions