I have an application with which I upload files, and subsequently those files are consulted; the files have the following nomenclature: EXAMPLE_7777_AAAA.pdf
If the file belongs to group 7777, the file is saved in the path: upload_to = 'Files / Group / 7777'
If the file belongs to group 7746, it is saved in the path: upload_to = 'Files / Group / 7746'
However, there are 31 groups, so I have to create 31 tables or models for to be able to save in each table the files belonging to each group.
The point is that I want to validate the group and from the group save the file in its specific path, with this the files will be stored in a single table.
That's how I do it
if grupo=='7777':
datos=ArchivosGrupo7777() # Nombre de la tabla actual
datos.usuario=usuarioSesion
datos.save()
if grupo=='7746':
datos=ArchivosGrupo7746() # Nombre de la tabla actual
datos.usuario=usuarioSesion
datos.save()
However the idea is that there are not too many tables and that it is something like this:
if grupo=='7777':
datos=Archivos()/*Nombre de la tabla
datos.usuario=usuarioSesion
datos.save(directorio='Archivos/Grupo/7777')
if grupo=='7746':
datos=Archivos()/*Nombre de la tabla
datos.usuario=usuarioSesion
datos.save(directorio='Archivos/Grupo/7746')
Modelos-Ejemplo
class ArchivosGrupo7777(models.Model):
fecha = models.DateField(auto_now_add=True)
proyecto=models.CharField(default='Proyecto 7777',max_length=30)
ruta = models.FileField(upload_to='Archivos/Grupo/7777')
usuario=models.ForeignKey(User)
class ArchivosGrupo7746(models.Model):
fecha = models.DateField(auto_now_add=True)
proyecto=models.CharField(default='Proyecto 7746',max_length=30)
ruta = models.FileField(upload_to='Archivos/Grupo/7746')
usuario=models.ForeignKey(User)