|
1 | | -"""filtersets for applicable web models""" |
| 1 | +"""filtersets for applicable app models""" |
2 | 2 |
|
| 3 | +from rest_framework_filters.filters import BooleanFilter, RelatedFilter |
| 4 | +from rest_framework_filters.filterset import FilterSet |
3 | 5 |
|
4 | 6 | # import models |
5 | | -# from web.models import () |
| 7 | +from web.models import ( |
| 8 | + Event, |
| 9 | + PresentationRequest, |
| 10 | + Resource, |
| 11 | + ResourceCategory, |
| 12 | + TopicSuggestion, |
| 13 | +) |
| 14 | + |
| 15 | + |
| 16 | +class EventFilterSet(FilterSet): |
| 17 | + """filterset class for Event""" |
| 18 | + |
| 19 | + class Meta: |
| 20 | + """Metaclass to define filterset model and fields""" |
| 21 | + |
| 22 | + model = Event |
| 23 | + fields = { |
| 24 | + "created_at": "__all__", |
| 25 | + "description": "__all__", |
| 26 | + "end_date_time": "__all__", |
| 27 | + "id": "__all__", |
| 28 | + "location": "__all__", |
| 29 | + "name": "__all__", |
| 30 | + "start_date_time": "__all__", |
| 31 | + "updated_at": "__all__", |
| 32 | + "url": "__all__", |
| 33 | + } |
| 34 | + |
| 35 | + |
| 36 | +class PresentationRequestFilterSet(FilterSet): |
| 37 | + """filterset class for PresentationRequest""" |
| 38 | + |
| 39 | + class Meta: |
| 40 | + """Metaclass to define filterset model and fields""" |
| 41 | + |
| 42 | + model = PresentationRequest |
| 43 | + fields = { |
| 44 | + "created_at": "__all__", |
| 45 | + "description": "__all__", |
| 46 | + "email": "__all__", |
| 47 | + "id": "__all__", |
| 48 | + "presenter": "__all__", |
| 49 | + "skill_level": "__all__", |
| 50 | + "title": "__all__", |
| 51 | + "updated_at": "__all__", |
| 52 | + } |
| 53 | + |
| 54 | + |
| 55 | +class ResourceFilterSet(FilterSet): |
| 56 | + """filterset class for Resource""" |
| 57 | + |
| 58 | + category = RelatedFilter( |
| 59 | + "ResourceCategoryFilterSet", field_name="category", queryset=ResourceCategory.objects.all() |
| 60 | + ) |
| 61 | + |
| 62 | + class Meta: |
| 63 | + """Metaclass to define filterset model and fields""" |
| 64 | + |
| 65 | + model = Resource |
| 66 | + fields = { |
| 67 | + "category": "__all__", |
| 68 | + "created_at": "__all__", |
| 69 | + "description": "__all__", |
| 70 | + "id": "__all__", |
| 71 | + "name": "__all__", |
| 72 | + "updated_at": "__all__", |
| 73 | + "url": "__all__", |
| 74 | + } |
| 75 | + |
| 76 | + |
| 77 | +class ResourceCategoryFilterSet(FilterSet): |
| 78 | + """filterset class for ResourceCategory""" |
| 79 | + |
| 80 | + resources = RelatedFilter("ResourceFilterSet", field_name="resources", queryset=Resource.objects.all()) |
| 81 | + has_resources = BooleanFilter(field_name="resources", lookup_expr="isnull", exclude=True) |
| 82 | + |
| 83 | + class Meta: |
| 84 | + """Metaclass to define filterset model and fields""" |
| 85 | + |
| 86 | + model = ResourceCategory |
| 87 | + fields = { |
| 88 | + "created_at": "__all__", |
| 89 | + "id": "__all__", |
| 90 | + "name": "__all__", |
| 91 | + "updated_at": "__all__", |
| 92 | + } |
| 93 | + |
| 94 | + |
| 95 | +class TopicSuggestionFilterSet(FilterSet): |
| 96 | + """filterset class for TopicSuggestion""" |
| 97 | + |
| 98 | + class Meta: |
| 99 | + """Metaclass to define filterset model and fields""" |
| 100 | + |
| 101 | + model = TopicSuggestion |
| 102 | + fields = { |
| 103 | + "created_at": "__all__", |
| 104 | + "description": "__all__", |
| 105 | + "email": "__all__", |
| 106 | + "id": "__all__", |
| 107 | + "skill_level": "__all__", |
| 108 | + "title": "__all__", |
| 109 | + "updated_at": "__all__", |
| 110 | + } |
0 commit comments