Working with FileFields/FieldFiles

24 views
Skip to first unread message

Hugo Kitano

unread,
Aug 21, 2015, 1:28:23 PM8/21/15
to Django users
Hi, I'm a beginner with Django, and I'm trying to figure out how to work with FieldFiles.

One of my models has a FileField in which the user must submit a .bed file.  I use another library in python to analyze the .bed file.
The .bed file is saved to a specific directory on disk, and I want

file_on_disk = Bed('/Users/.../media/statistics.bed')

where statistics.bed is the name of the file, and media is the directory all files are saved to.  How would I construct this line of code?

Thanks!

Hugo Osvaldo Barrera

unread,
Aug 22, 2015, 5:55:03 PM8/22/15
to django...@googlegroups.com
You're probably after the upload_to argument of FileField, which let you define where files are saved:
 
 
(I assume you're already looked into MEDIA_ROOT):
 
 
--
Hugo Osvaldo Barrera
 
Message has been deleted

Hugo Osvaldo Barrera

unread,
Aug 25, 2015, 2:03:57 PM8/25/15
to Hugo Kitano, Django users
 
 
 
On Tue, Aug 25, 2015, at 14:31, Hugo Kitano wrote:
I guess my question is more "dumb" than that.  I need a concatenated string "ab" where a is given and b is the name of a file uploaded to a field in a model.
 
Thanks!
 
Something like this?
 
    class Blah(models.Model):
        def upload_to(self, filename="untitled", instance=None):
            return "somestring" + filename
 
        data = FileField(upload_to=upload_to)
--
Hugo Osvaldo Barrera
 
Reply all
Reply to author
Forward
0 new messages