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