I'm importing a set of pre-existing Django files, and I'd like to reference them in my templates (which use FileField
or ImageField
). For example, one of my templates looks like this:
class Imagem(models.Model):
arquivo = ImageField(upload_to=u"img/%Y/%m/%d")
miniatura = ImageField(upload_to=u"img/thumb/%Y/%m/%d")
...
And I have several images (already copied to my MEDIA_ROOT
) like this:
MEDIA_ROOT
|- gallery
|-album1
|-foto1.jpg
|-foto2.jpg
|-...
|-thumbs
|-thumbs_foto1.jpg
|-thumbs_foto2.jpg
|-...
(Note that the images are not under the folder upload_to
, but in another completely different)
Is it possible to create instances of this template by referring to preexisting images without having to make copies of them and without having to rename them and / or move them? And what would be the command to create these instances?
I have no problem navigating the file system, finding the names of the images and associating each image with its thumbnail, my problem is how to create the template itself:
path_imagem = os.path.join(settings.MEDIA_ROOT, 'gallery/album1/foto1.jpg')
path_miniatura = os.path.join(settings.MEDIA_ROOT, 'gallery/album1/thumbs/thumbs_foto1.jpg')
Imagem.objects.create(???)
The examples in the Django documentation (eg FileField
, "File Uploads" , Managing Files " ) are all referring to new files, where you create a File
or if you get one from an upload, for example. In my case the files already exist and are already under MEDIA_ROOT
.