Created
July 23, 2020 17:54
-
-
Save walison17/91a9a6f8c293885fcead6c98ce1fb2c9 to your computer and use it in GitHub Desktop.
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 Analisador(models.Model): | |
| nome = models.CharField(max_length=50) | |
| def __str__(self): | |
| return self.nome | |
| def diretorio_anexo(instance, filename): | |
| return f'anexos/{instance.analisador_id}/{filename}' | |
| class Anexo(models.Model): | |
| arquivo = models.FileField(upload_to=diretorio_anexo) | |
| analisador = models.ForeignKey(Analisador, related_name="anexos", on_delete=models.PROTECT) | |
| anexos = analisador.anexos.all() | |
| urls = [anexo.arquivo.url for anexo in anexos] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment