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

Add search fields to endpoints that lack them #313

Merged
merged 17 commits into from
Oct 2, 2023
Merged
Changes from 16 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
22 changes: 16 additions & 6 deletions api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class DocumentViewSet(viewsets.ReadOnlyModelViewSet):
})
queryset = models.Document.objects.all()
serializer_class = serializers.DocumentSerializer
search_fields = ['title', 'desc']
filterset_fields = (
'slug',
'title',
Expand Down Expand Up @@ -142,7 +143,7 @@ class SpellViewSet(viewsets.ReadOnlyModelViewSet):
queryset = models.Spell.objects.all()
filterset_class=SpellFilter
serializer_class = serializers.SpellSerializer
search_fields = ['dnd_class', 'name']
search_fields = ['dnd_class', 'name', 'desc']
ordering_fields = '__all__'
ordering=['name']
filterset_fields = (
Expand Down Expand Up @@ -186,6 +187,7 @@ class SpellListViewSet(viewsets.ReadOnlyModelViewSet):
queryset = models.SpellList.objects.all()
serializer_class = serializers.SpellListSerializer
filterset_class = SpellListFilter
search_fields = ['name', 'desc']

class MonsterFilter(django_filters.FilterSet):

Expand Down Expand Up @@ -219,7 +221,7 @@ class MonsterViewSet(viewsets.ReadOnlyModelViewSet):
filterset_class = MonsterFilter

serializer_class = serializers.MonsterSerializer
search_fields = ['name']
search_fields = ['name', 'desc']

class BackgroundFilter(django_filters.FilterSet):

Expand Down Expand Up @@ -254,7 +256,7 @@ class BackgroundViewSet(viewsets.ReadOnlyModelViewSet):
ordering_fields = '__all__'
ordering = ['name']
filterset_class = BackgroundFilter
search_fields = ['name']
search_fields = ['name', 'desc']

class PlaneFilter(django_filters.FilterSet):

Expand Down Expand Up @@ -282,6 +284,7 @@ class PlaneViewSet(viewsets.ReadOnlyModelViewSet):
queryset = models.Plane.objects.all()
serializer_class = serializers.PlaneSerializer
filterset_class=PlaneFilter
search_fields = ['name', 'desc']

class SectionFilter(django_filters.FilterSet):

Expand Down Expand Up @@ -312,6 +315,7 @@ class SectionViewSet(viewsets.ReadOnlyModelViewSet):
ordering_fields = '__all__'
ordering=['name']
filterset_class = SectionFilter
search_fields = ['name', 'desc']

class FeatFilter(django_filters.FilterSet):

Expand Down Expand Up @@ -339,6 +343,7 @@ class FeatViewSet(viewsets.ReadOnlyModelViewSet):
queryset = models.Feat.objects.all()
serializer_class = serializers.FeatSerializer
filterset_class = FeatFilter
search_fields = ['name', 'desc']

class ConditionFilter(django_filters.FilterSet):

Expand All @@ -365,6 +370,7 @@ class ConditionViewSet(viewsets.ReadOnlyModelViewSet):
)
queryset = models.Condition.objects.all()
serializer_class = serializers.ConditionSerializer
search_fields = ['name', 'desc']
filterset_fields=(
'name',
'document__slug',
Expand Down Expand Up @@ -404,6 +410,7 @@ class RaceViewSet(viewsets.ReadOnlyModelViewSet):
queryset = models.Race.objects.all()
serializer_class = serializers.RaceSerializer
filterset_class = RaceFilter
search_fields = ['name', 'desc']

class SubraceFilter(django_filters.FilterSet):
# Unused, but could be implemented later.
Expand Down Expand Up @@ -431,6 +438,7 @@ class SubraceViewSet(viewsets.ReadOnlyModelViewSet):
)
queryset = models.Subrace.objects.all()
serializer_class = serializers.SubraceSerializer
search_fields = ['name', 'desc']
filterset_fields=(
'name',
'document__slug',
Expand Down Expand Up @@ -472,6 +480,7 @@ class CharClassViewSet(viewsets.ReadOnlyModelViewSet):
queryset = models.CharClass.objects.all()
serializer_class = serializers.CharClassSerializer
filterset_class = CharClassFilter
search_fields = ['name', 'desc']

class ArchetypeFilter(django_filters.FilterSet):
# Unused but could be implemented later.
Expand Down Expand Up @@ -499,6 +508,7 @@ class ArchetypeViewSet(viewsets.ReadOnlyModelViewSet):
)
queryset = models.Archetype.objects.all()
serializer_class = serializers.ArchetypeSerializer
search_fields = ['name', 'desc']
filterset_fields=(
'name',
'document__slug',
Expand Down Expand Up @@ -533,7 +543,7 @@ class MagicItemViewSet(viewsets.ReadOnlyModelViewSet):
queryset = models.MagicItem.objects.all()
serializer_class = serializers.MagicItemSerializer
filterset_class = MagicItemFilter
search_fields = ['name']
search_fields = ['name', 'desc']

class WeaponFilter(django_filters.FilterSet):

Expand Down Expand Up @@ -565,7 +575,7 @@ class WeaponViewSet(viewsets.ReadOnlyModelViewSet):
queryset = models.Weapon.objects.all()
serializer_class = serializers.WeaponSerializer
filterset_class = WeaponFilter
search_fields = ['name']
search_fields = ['name', 'desc']

class ArmorFilter(django_filters.FilterSet):

Expand Down Expand Up @@ -595,4 +605,4 @@ class ArmorViewSet(viewsets.ReadOnlyModelViewSet):
queryset = models.Armor.objects.all()
serializer_class = serializers.ArmorSerializer
filterset_class = ArmorFilter
search_fields = ['name']
search_fields = ['name', 'desc']