Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

some more api changes

Jonas Winklere1ae068cda2a
diff --git a/src/documents/admin.py b/src/documents/admin.py
index b96487937..18bf562f9 100755
--- a/src/documents/admin.py
+++ b/src/documents/admin.py
@@ -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):
diff --git a/src/documents/serialisers.py b/src/documents/serialisers.py
index 92b804f1b..81d2f6c36 100644
--- a/src/documents/serialisers.py
+++ b/src/documents/serialisers.py
@@ -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"
)
diff --git a/src/documents/views.py b/src/documents/views.py
index f318d9b28..1f402d8d5 100755
--- a/src/documents/views.py
+++ b/src/documents/views.py
@@ -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,