Skip to content

Instantly share code, notes, and snippets.

@walison17
Created July 23, 2020 17:54
Show Gist options
  • Select an option

  • Save walison17/91a9a6f8c293885fcead6c98ce1fb2c9 to your computer and use it in GitHub Desktop.

Select an option

Save walison17/91a9a6f8c293885fcead6c98ce1fb2c9 to your computer and use it in GitHub Desktop.
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