Created
September 18, 2021 14:58
-
-
Save guilhermecarvalhocarneiro/2b553a0c11de1e90f2031ff50100ddbe to your computer and use it in GitHub Desktop.
Classe de imagem com efeito
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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