Skip to content

Commit

Permalink
Change in curriculo model to upload as raw file
Browse files Browse the repository at this point in the history
  • Loading branch information
FredMagas committed Aug 9, 2024
1 parent 2fcd75a commit ccd41fb
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions fredmagaweb/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.db import models
from django.conf import settings
from cloudinary.uploader import upload

class Contato(models.Model):
nome = models.CharField(max_length=40)
Expand All @@ -25,14 +26,16 @@ class Curriculo(models.Model):
arquivo = models.FileField(upload_to='curriculos/')
data_upload = models.DateTimeField(auto_now_add=True)

def __str__(self):
return f"Curriculo {self.id} - {self.data_upload.strftime('%d/%m/%Y')}"

def save(self, *args, **kwargs):
# Garantir que o arquivo PDF seja tratado como 'raw'
self.arquivo.upload_options = {'resource_type': 'raw'}
# Usar o Cloudinary uploader diretamente para garantir que o arquivo seja tratado como 'raw'
if self.arquivo and not self.pk:
upload_result = upload(self.arquivo, resource_type="raw")
self.arquivo.name = upload_result['public_id'] + '.' + upload_result['format']
super().save(*args, **kwargs)

# class Meta:
# verbose_name = "Currículo"
# verbose_name_plural = "Currículos"
def __str__(self):
return f"Curriculo {self.id} - {self.data_upload.strftime('%d/%m/%Y')}"

class Meta:
verbose_name = "Currículo"
verbose_name_plural = "Currículos"

0 comments on commit ccd41fb

Please sign in to comment.