diff options
author | Stephen Finucane <stephen@that.guru> | 2018-04-11 17:13:37 +0100 |
---|---|---|
committer | Daniel Axtens <dja@axtens.net> | 2018-05-10 02:22:18 +1000 |
commit | 30a5f17b5b8dbd42822c9f8eb4e222606ca43d6a (patch) | |
tree | 9f3fd849cc722b17aa30275c2b976a0d8b615e5d | |
parent | f3c02f36d6fcaac5f3bad5aef6a83356b89eeda6 (diff) | |
download | patchwork-30a5f17b5b8dbd42822c9f8eb4e222606ca43d6a.tar patchwork-30a5f17b5b8dbd42822c9f8eb4e222606ca43d6a.tar.gz |
REST: Use ModelMultipleChoiceField for other fields
There's benefit to being able to do stuff like select multiple patches.
Let's do that.
Signed-off-by: Stephen Finucane <stephen@that.guru>
Signed-off-by: Daniel Axtens <dja@axtens.net>
-rw-r--r-- | patchwork/api/filters.py | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/patchwork/api/filters.py b/patchwork/api/filters.py index afef10f..4d8d504 100644 --- a/patchwork/api/filters.py +++ b/patchwork/api/filters.py @@ -41,6 +41,9 @@ from patchwork.models import State class ModelMultipleChoiceField(BaseMultipleChoiceField): def _get_filter(self, value): + if not self.alternate_lookup: + return 'pk', value + try: return 'pk', int(value) except ValueError: @@ -88,14 +91,14 @@ class ModelMultipleChoiceField(BaseMultipleChoiceField): return qs -class ProjectChoiceField(ModelMultipleChoiceField): +class BaseField(ModelMultipleChoiceField): - alternate_lookup = 'linkname__iexact' + alternate_lookup = None -class ProjectFilter(ModelMultipleChoiceFilter): +class BaseFilter(ModelMultipleChoiceFilter): - field_class = ProjectChoiceField + field_class = BaseField class PersonChoiceField(ModelMultipleChoiceField): @@ -108,6 +111,16 @@ class PersonFilter(ModelMultipleChoiceFilter): field_class = PersonChoiceField +class ProjectChoiceField(ModelMultipleChoiceField): + + alternate_lookup = 'linkname__iexact' + + +class ProjectFilter(ModelMultipleChoiceFilter): + + field_class = ProjectChoiceField + + class StateChoiceField(ModelMultipleChoiceField): def _get_filter(self, value): @@ -154,6 +167,7 @@ class SeriesFilterSet(TimestampMixin, FilterSet): class CoverLetterFilterSet(TimestampMixin, FilterSet): project = ProjectFilter(queryset=Project.objects.all()) + series = BaseFilter(queryset=Project.objects.all()) submitter = PersonFilter(queryset=Person.objects.all()) class Meta: @@ -164,6 +178,7 @@ class CoverLetterFilterSet(TimestampMixin, FilterSet): class PatchFilterSet(TimestampMixin, FilterSet): project = ProjectFilter(queryset=Project.objects.all()) + series = BaseFilter(queryset=Series.objects.all()) submitter = PersonFilter(queryset=Person.objects.all()) delegate = UserFilter(queryset=User.objects.all()) state = StateFilter(queryset=State.objects.all()) @@ -186,6 +201,9 @@ class CheckFilterSet(TimestampMixin, FilterSet): class EventFilterSet(TimestampMixin, FilterSet): project = ProjectFilter(queryset=Project.objects.all()) + series = BaseFilter(queryset=Series.objects.all()) + patch = BaseFilter(queryset=Patch.objects.all()) + cover = BaseFilter(queryset=CoverLetter.objects.all()) class Meta: model = Event |