mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Fix implementation of django-filter
This commit is contained in:
		| @@ -1,8 +1,14 @@ | ||||
| from django_filters.rest_framework import CharFilter, FilterSet, BooleanFilter | ||||
| from django_filters.rest_framework import CharFilter, FilterSet, BooleanFilter, ModelChoiceFilter | ||||
|  | ||||
| from .models import Correspondent, Document, Tag | ||||
|  | ||||
|  | ||||
| CHAR_KWARGS = ( | ||||
|     "startswith", "endswith", "contains", | ||||
|     "istartswith", "iendswith", "icontains" | ||||
| ) | ||||
|  | ||||
|  | ||||
| class CorrespondentFilterSet(FilterSet): | ||||
|  | ||||
|     class Meta: | ||||
| @@ -31,34 +37,24 @@ class TagFilterSet(FilterSet): | ||||
|  | ||||
| class DocumentFilterSet(FilterSet): | ||||
|  | ||||
|     CHAR_KWARGS = { | ||||
|         "lookup_expr": ( | ||||
|             "startswith", | ||||
|             "endswith", | ||||
|             "contains", | ||||
|             "istartswith", | ||||
|             "iendswith", | ||||
|             "icontains" | ||||
|         ) | ||||
|     } | ||||
|  | ||||
|     correspondent__name = CharFilter( | ||||
|         field_name="correspondent__name", **CHAR_KWARGS) | ||||
|     correspondent__slug = CharFilter( | ||||
|         field_name="correspondent__slug", **CHAR_KWARGS) | ||||
|     tags__name = CharFilter( | ||||
|         field_name="tags__name", **CHAR_KWARGS) | ||||
|     tags__slug = CharFilter( | ||||
|         field_name="tags__slug", **CHAR_KWARGS) | ||||
|     tags__empty = BooleanFilter( | ||||
|         field_name="tags", lookup_expr="isnull", distinct=True) | ||||
|     tags_empty = BooleanFilter( | ||||
|         label="Is tagged", | ||||
|         field_name="tags", | ||||
|         lookup_expr="isnull", | ||||
|         exclude=True | ||||
|     ) | ||||
|  | ||||
|     class Meta: | ||||
|         model = Document | ||||
|         fields = { | ||||
|             "title": [ | ||||
|                 "startswith", "endswith", "contains", | ||||
|                 "istartswith", "iendswith", "icontains" | ||||
|             ], | ||||
|             "content": ["contains", "icontains"], | ||||
|  | ||||
|             "title": CHAR_KWARGS, | ||||
|             "content": ("contains", "icontains"), | ||||
|  | ||||
|             "correspondent__name": CHAR_KWARGS, | ||||
|             "correspondent__slug": CHAR_KWARGS, | ||||
|  | ||||
|             "tags__name": CHAR_KWARGS, | ||||
|             "tags__slug": CHAR_KWARGS, | ||||
|  | ||||
|         } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Daniel Quinn
					Daniel Quinn