MEDIA_ROOT/MEDIA_URL settings, with Supabase Storage as the recommended remote backend). file_type and file_size are computed automatically at save time from the uploaded file.
The backend also exposes an experimental GET /api/documents/{id}/document_content/ endpoint that extracts and renders text content from PDF files (via PyPDF2) and Excel files (via openpyxl). This endpoint is currently marked as in development and is not production-ready.
On the frontend, documents are rendered using react-pdf, which supports inline PDF preview without downloading.
No permission classes are enforced in the current codebase — all endpoints are currently accessible without authentication. Apply
IsAuthenticatedAndRole or equivalent before deploying write operations to production.The Documents object
Unique identifier for the document.
Document title (max 255 characters). Maps to the
Título admin label.Plain-text description of the document’s content or purpose. Maps to the
Descripción admin label.Publication date in
YYYY-MM-DD format. Records are ordered by descending fecha by default.File extension detected at upload time (e.g.
pdf, xlsx, docx). Set automatically — do not send in requests.Human-readable file size computed at upload time (e.g.
1.24 MB, 340.50 KB). Set automatically — do not send in requests.Uppercased version of
file_type (e.g. PDF, XLSX). Computed by the serializer.Alias for
file_size exposed by the serializer. Falls back to N/A if unknown.Absolute URL to download the document file. Constructed from the request context at serialization time.
List documents
Upload a document
multipart/form-data because the request includes a file field. file_type and file_size are detected automatically from the uploaded file and must not be included in the request.
Document title. Maximum 255 characters.
Description of the document.
Publication date in
YYYY-MM-DD format.The file to upload. PDF files are supported for inline preview via
react-pdf on the frontend. Excel files (.xlsx, .xls) are supported by the experimental content extraction endpoint. Files are stored under the documentos/ media path.201 Created
Retrieve a document
The numeric ID of the document.
Update a document
PUT replaces the full record. PATCH applies a partial update — only supply the fields you want to change.
The numeric ID of the document to update.
Updated document title.
Updated description.
Updated publication date (
YYYY-MM-DD).Replacement file. When provided,
file_type and file_size are recomputed automatically.Delete a document
The numeric ID of the document to delete.
204 No Content on success.
Extract document content (experimental)
This endpoint is marked as in development in the source code and is not production-ready. It renders extracted text as HTML via a Django template (
document_content.html).- PDF — text is extracted page by page using
PyPDF2and wrapped in<p>tags. - Excel (
.xlsx/.xls) — all sheets are rendered as an HTML<table>usingopenpyxl. - Other file types — returns
400 Bad Requestwith{"error": "Unsupported file type."}.
The numeric ID of the document whose content should be extracted.
| Status | Body | Condition |
|---|---|---|
400 | {"error": "Unsupported file type."} | File is not PDF or Excel |
404 | {"error": "Document not found."} | No document with the given ID |
500 | {"error": "..."} | Error reading or parsing the file |
File storage
Files uploaded viaPOST /api/documents/ are written to the documentos/ subdirectory within Django’s configured media storage. For production deployments, the project uses Supabase Storage as the remote file backend, which means the url field in responses will resolve to a Supabase-hosted URL rather than a local server path.
The frontend uses the react-pdf library to render PDF documents inline — no separate download is required for PDF previews.