Skip to content

Instantly share code, notes, and snippets.

@guilhermecarvalhocarneiro
Created September 18, 2021 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guilhermecarvalhocarneiro/2b553a0c11de1e90f2031ff50100ddbe to your computer and use it in GitHub Desktop.
Save guilhermecarvalhocarneiro/2b553a0c11de1e90f2031ff50100ddbe to your computer and use it in GitHub Desktop.
Classe de imagem com efeito
class ImagemEfeito(Base):
resultado = models.ForeignKey(Resultado, on_delete=models.CASCADE, related_name="imagens_efeito_resultado")
imagem_resultado = models.ForeignKey(ImagemResultado, on_delete=models.CASCADE, null=True, blank=True,
related_name="imagens_efeito_imagem_resultado")
imagem = models.TextField()
def get_path_image(self):
return f"/media/results/images/{self.imagem}"
@staticmethod
def save_image_with_effect(resultado_id: str, path:str, imagem_resultado_id: str):
"""Método para salvar as imagens após a aplicação dos efeitos"""
try:
resultado = Resultado.objects.get(id=resultado_id)
imagem_resultado = ImagemResultado.objects.get(id=imagem_resultado_id)
ImagemEfeito.objects.create(resultado=resultado, imagem_resultado=imagem_resultado, imagem=path)
except Exception as error:
raise Exception(f"Erro ao executar o sage_image_with_effect de ImagemEfeito : {error}")
def __str__(self):
return f"{self.imagem}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment