mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	some more api changes
This commit is contained in:
		| @@ -83,72 +83,38 @@ class CorrespondentAdmin(CommonAdmin): | ||||
|  | ||||
|     list_display = ( | ||||
|         "name", | ||||
|         "automatic_classification", | ||||
|         "document_count", | ||||
|         "last_correspondence" | ||||
|         "automatic_classification" | ||||
|     ) | ||||
|     list_editable = ("automatic_classification",) | ||||
|  | ||||
|     readonly_fields = ("slug",) | ||||
|  | ||||
|     def get_queryset(self, request): | ||||
|         qs = super(CorrespondentAdmin, self).get_queryset(request) | ||||
|         qs = qs.annotate( | ||||
|             document_count=models.Count("documents"), | ||||
|             last_correspondence=models.Max("documents__created") | ||||
|         ) | ||||
|         return qs | ||||
|  | ||||
|     def document_count(self, obj): | ||||
|         return obj.document_count | ||||
|     document_count.admin_order_field = "document_count" | ||||
|  | ||||
|     def last_correspondence(self, obj): | ||||
|         return obj.last_correspondence | ||||
|     last_correspondence.admin_order_field = "last_correspondence" | ||||
|  | ||||
|  | ||||
| class TagAdmin(CommonAdmin): | ||||
|  | ||||
|     list_display = ( | ||||
|         "name", | ||||
|         "colour", | ||||
|         "automatic_classification", | ||||
|         "document_count") | ||||
|         "automatic_classification" | ||||
|     ) | ||||
|  | ||||
|     list_filter = ("colour",) | ||||
|     list_editable = ("colour", "automatic_classification") | ||||
|  | ||||
|     readonly_fields = ("slug",) | ||||
|  | ||||
|     class Media: | ||||
|         js = ("js/colours.js",) | ||||
|  | ||||
|     def get_queryset(self, request): | ||||
|         qs = super(TagAdmin, self).get_queryset(request) | ||||
|         qs = qs.annotate(document_count=models.Count("documents")) | ||||
|         return qs | ||||
|  | ||||
|     def document_count(self, obj): | ||||
|         return obj.document_count | ||||
|     document_count.admin_order_field = "document_count" | ||||
|  | ||||
|  | ||||
| class DocumentTypeAdmin(CommonAdmin): | ||||
|  | ||||
|     list_display = ("name", "automatic_classification", "document_count") | ||||
|     list_display = ( | ||||
|         "name", | ||||
|         "automatic_classification" | ||||
|     ) | ||||
|  | ||||
|     list_editable = ("automatic_classification",) | ||||
|  | ||||
|     readonly_fields = ("slug",) | ||||
|  | ||||
|     def get_queryset(self, request): | ||||
|         qs = super(DocumentTypeAdmin, self).get_queryset(request) | ||||
|         qs = qs.annotate(document_count=models.Count("documents")) | ||||
|         return qs | ||||
|  | ||||
|     def document_count(self, obj): | ||||
|         return obj.document_count | ||||
|     document_count.admin_order_field = "document_count" | ||||
|  | ||||
|  | ||||
| class DocumentAdmin(CommonAdmin): | ||||
|  | ||||
|   | ||||
| @@ -5,30 +5,41 @@ from .models import Correspondent, Tag, Document, Log, DocumentType | ||||
|  | ||||
| class CorrespondentSerializer(serializers.HyperlinkedModelSerializer): | ||||
|  | ||||
|     document_count = serializers.IntegerField(read_only=True) | ||||
|  | ||||
|     last_correspondence = serializers.DateTimeField(read_only=True) | ||||
|  | ||||
|     class Meta: | ||||
|         model = Correspondent | ||||
|         fields = ( | ||||
|             "id", | ||||
|             "slug", | ||||
|             "name", | ||||
|             "automatic_classification" | ||||
|             "automatic_classification", | ||||
|             "document_count", | ||||
|             "last_correspondence" | ||||
|         ) | ||||
|  | ||||
|  | ||||
| class DocumentTypeSerializer(serializers.HyperlinkedModelSerializer): | ||||
|  | ||||
|     document_count = serializers.IntegerField(read_only=True) | ||||
|  | ||||
|     class Meta: | ||||
|         model = DocumentType | ||||
|         fields = ( | ||||
|             "id", | ||||
|             "slug", | ||||
|             "name", | ||||
|             "automatic_classification" | ||||
|             "automatic_classification", | ||||
|             "document_count" | ||||
|         ) | ||||
|  | ||||
|  | ||||
| class TagSerializer(serializers.HyperlinkedModelSerializer): | ||||
|  | ||||
|     document_count = serializers.IntegerField(read_only=True) | ||||
|  | ||||
|     class Meta: | ||||
|         model = Tag | ||||
|         fields = ( | ||||
| @@ -37,7 +48,8 @@ class TagSerializer(serializers.HyperlinkedModelSerializer): | ||||
|             "name", | ||||
|             "colour", | ||||
|             "automatic_classification", | ||||
|             "is_inbox_tag" | ||||
|             "is_inbox_tag", | ||||
|             "document_count" | ||||
|         ) | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -1,3 +1,4 @@ | ||||
| from django.db.models import Count, Max | ||||
| from django.http import HttpResponse, HttpResponseBadRequest | ||||
| from django.views.generic import DetailView, FormView, TemplateView | ||||
| from django_filters.rest_framework import DjangoFilterBackend | ||||
| @@ -109,35 +110,35 @@ class PushView(SessionOrBasicAuthMixin, FormView): | ||||
|  | ||||
| class CorrespondentViewSet(ModelViewSet): | ||||
|     model = Correspondent | ||||
|     queryset = Correspondent.objects.all() | ||||
|     queryset = Correspondent.objects.annotate(document_count=Count('documents'), last_correspondence=Max('documents__created')) | ||||
|     serializer_class = CorrespondentSerializer | ||||
|     pagination_class = StandardPagination | ||||
|     permission_classes = (IsAuthenticated,) | ||||
|     filter_backends = (DjangoFilterBackend, OrderingFilter) | ||||
|     filter_class = CorrespondentFilterSet | ||||
|     ordering_fields = ("name", "slug") | ||||
|     ordering_fields = ("name", "document_count", "last_correspondence") | ||||
|  | ||||
|  | ||||
| class TagViewSet(ModelViewSet): | ||||
|     model = Tag | ||||
|     queryset = Tag.objects.all() | ||||
|     queryset = Tag.objects.annotate(document_count=Count('documents')) | ||||
|     serializer_class = TagSerializer | ||||
|     pagination_class = StandardPagination | ||||
|     permission_classes = (IsAuthenticated,) | ||||
|     filter_backends = (DjangoFilterBackend, OrderingFilter) | ||||
|     filter_class = TagFilterSet | ||||
|     ordering_fields = ("name", "slug") | ||||
|     ordering_fields = ("name", "document_count") | ||||
|  | ||||
|  | ||||
| class DocumentTypeViewSet(ModelViewSet): | ||||
|     model = DocumentType | ||||
|     queryset = DocumentType.objects.all() | ||||
|     queryset = DocumentType.objects.annotate(document_count=Count('documents')) | ||||
|     serializer_class = DocumentTypeSerializer | ||||
|     pagination_class = StandardPagination | ||||
|     permission_classes = (IsAuthenticated,) | ||||
|     filter_backends = (DjangoFilterBackend, OrderingFilter) | ||||
|     filter_class = DocumentTypeFilterSet | ||||
|     ordering_fields = ("name", "slug") | ||||
|     ordering_fields = ("name", "document_count") | ||||
|  | ||||
|  | ||||
| class DocumentViewSet(RetrieveModelMixin, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Jonas Winkler
					Jonas Winkler