-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started working on the filtering for status and status for feedback
- Loading branch information
Showing
3 changed files
with
111 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from django.db.models import Q | ||
from django_filters import rest_framework as filters | ||
from django_filters.rest_framework import OrderingFilter | ||
|
||
from app.feedback.models import Feedback | ||
from app.feedback.models.bug import Bug | ||
from app.feedback.models.idea import Idea | ||
|
||
|
||
class FeedbackFilter(filters.FilterSet): | ||
|
||
feedback_type = filters.CharFilter( | ||
method="fiter_feedback_type", label="List of feedback type" | ||
) | ||
|
||
status = filters.ModelChoiceFilter( | ||
method="filter_status", | ||
field_name="status", | ||
label="List of feedback status", | ||
queryset=Feedback.objects.all(), | ||
) | ||
|
||
ordering = OrderingFilter( | ||
fields=( | ||
"created_at", | ||
"updated_at", | ||
) | ||
) | ||
|
||
def fiter_feedback_type(self, queryset, _name, feedback_type): | ||
|
||
if feedback_type == "Idea": | ||
return queryset.filter(Q(instance_of=Idea)) | ||
|
||
elif feedback_type == "Bug": | ||
return queryset.filter(Q(instance_of=Bug)) | ||
|
||
else: | ||
return queryset | ||
|
||
def filter_status(self, queryset, _name, value): | ||
return queryset.filter(status=value) | ||
|
||
class Meta: | ||
model = Feedback | ||
fields = [ | ||
"title", | ||
"author", | ||
"status", | ||
"created_at", | ||
"updated_at", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters