DocManagerBackend/docmanager_backend/documents/models.py

32 lines
926 B
Python
Raw Normal View History

2024-11-23 23:02:52 +08:00
from django.db import models
from django.utils.timezone import now
import uuid
class Document(models.Model):
name = models.CharField(max_length=100)
DOCUMENT_TYPE_CHOICES = (
("pdf", "PDF"),
("image", "Image"),
("video", "Video"),
("doc", "Word Document"),
("excel", "Excel Document"),
("ppt", "Powerpoint Document"),
)
document_type = models.CharField(
max_length=32, choices=DOCUMENT_TYPE_CHOICES, null=False, blank=False
)
2024-11-24 02:20:18 +08:00
number_pages = models.IntegerField(null=False, blank=False)
2024-11-23 23:02:52 +08:00
def upload_to(instance, filename):
_, extension = filename.split(".")
2024-11-24 02:20:18 +08:00
return "documents/%s_%s.%s" % (now(), str(uuid.uuid4()), extension)
2024-11-23 23:02:52 +08:00
file = models.FileField(upload_to=upload_to)
date_uploaded = models.DateTimeField(default=now, editable=False)
def __str__(self):
2024-11-24 02:20:18 +08:00
return f"{self.name} ({self.document_type})"