Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TP2000-1600 Add Subtask filter to Task admin view #1344

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion tasks/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,29 @@ def link_to_workbasket(self, workbasket):
)


class SubtaskFilter(admin.SimpleListFilter):
title = "Subtasks"
parameter_name = "is_subtask"

def lookups(self, request, model_admin):
return (
("TRUE", "Subtasks"),
("FALSE", "Tasks"),
)

def queryset(self, request, queryset):
value = self.value()
if value == "TRUE":
return queryset.exclude(parent_task=None)
elif value == "FALSE":
return queryset.filter(parent_task=None)


class TaskAdmin(TaskAdminMixin, admin.ModelAdmin):
list_display = [
"id",
"title",
"is_subtask",
"description",
"category",
"progress_state",
Expand All @@ -41,7 +60,11 @@ class TaskAdmin(TaskAdminMixin, admin.ModelAdmin):
"creator",
]
search_fields = ["id", "title", "description"]
list_filter = ["category", "progress_state"]
list_filter = (
SubtaskFilter,
"category",
"progress_state",
)

def parent_task_id(self, obj):
if not obj.parent_task:
Expand Down
2 changes: 2 additions & 0 deletions tasks/models/task.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime

from django.conf import settings
from django.contrib import admin
from django.contrib.auth import get_user_model
from django.db import models
from django.db import transaction
Expand Down Expand Up @@ -95,6 +96,7 @@ class Task(TaskBase):
objects = TaskManager.from_queryset(TaskQueryset)()

@property
@admin.display(boolean=True)
def is_subtask(self) -> bool:
return bool(self.parent_task)

Expand Down