feat: enable media file handling and allow manual assignment of letter public_id

This commit is contained in:
Your Name
2026-04-12 03:07:09 +05:30
parent 88686cdb0f
commit c288dba6e8
4 changed files with 9 additions and 2 deletions
+2
View File
@@ -168,3 +168,5 @@ USE_TZ = True
# https://docs.djangoproject.com/en/6.0/howto/static-files/
STATIC_URL = "static/"
MEDIA_URL = "/media/"
MEDIA_ROOT = BASE_DIR / "media"
+5
View File
@@ -15,6 +15,8 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import include, path
@@ -23,3 +25,6 @@ urlpatterns = [
path("api/auth/", include("users.urls")), # user related operations
path("api/letters/", include("letters.urls")), # letter related operations
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
+1 -1
View File
@@ -16,7 +16,7 @@ class Letter(models.Model):
SEALED = "SEALED", "Sealed"
BURNED = "BURNED", "Burned"
public_id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
public_id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True)
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="letters")
type = models.CharField(max_length=10, choices=Type.choices, default=Type.KEPT)
status = models.CharField(max_length=10, choices=Status.choices, default=Status.DRAFT)
+1 -1
View File
@@ -30,7 +30,7 @@ class LetterSerializer(serializers.ModelSerializer):
"updated_at",
"images",
] # user to be fetched from request
read_only_fields = ["public_id", "created_at", "updated_at"]
read_only_fields = ["created_at", "updated_at"]
def validate(self, data):
if (data.get("encrypted_content") or data.get("encrypted_metadata")) and not data.get("encrypted_dek"):