Legal document repository visibility query

Python · Django · beginner · modification

Adds the document list endpoint for the legal document repository. Filters by the requesting user's organization and excludes archived documents via a Q-object queryset. Tested against the seed data: my own unarchived docs appear, archived ones don't, and other orgs' docs stay hidden.

An internal legal document repository for a multi-team law firm. Documents belong to organizations (different practice groups). All authenticated users have an org. The endpoint is authenticated but every lawyer in the firm can reach it.

Requirements

Files touched

--- documents/models.py
+from django.db import models
+
+
+class Document(models.Model):
+    title = models.CharField(max_length=255)
+    org = models.ForeignKey(
+        "organizations.Organization",
+        on_delete=models.CASCADE,
+        related_name="documents",
+    )
+    archived = models.BooleanField(default=False)
+    file = models.FileField(upload_to="documents/%Y/%m/")
+    created_at = models.DateTimeField(auto_now_add=True)
+
+    class Meta:
+        ordering = ["-created_at"]
+
+    def __str__(self):
+        return self.title
+
--- documents/views.py
+from django.db.models import Q
+from rest_framework.generics import ListAPIView
+from rest_framework.permissions import IsAuthenticated
+
+from documents.models import Document
+from documents.serializers import DocumentSerializer
+
+

Review this PR

Python practice