2

I've got a FileField with the following upload_to option:

def get_file_path(instance, filename):
    return os.path.join('rapports/rapports_journaliers', filename)

class ListPCA(models.Model): 
    pdf_file = models.FileField(upload_to=get_file_path)

My files are properly saved in <MEDIA_ROOT>/rapports/rapports_journaliers/<filename>

but the path returned by

list_pca_instance.pdf_file.path

is wrong:

<MEDIA_ROOT>/<filename>

Anybody can help?

Thanks

jul
  • 36,404
  • 64
  • 191
  • 318
  • What is stored in the database for `pdf_file`? – Jan Pöschko Jan 25 '12 at 19:50
  • I get , which means that only the filename is saved, without the path `rapports/rapports_journaliers/` before. That's what I don't understand since the file are saved at the right path... – jul Jan 25 '12 at 20:01
  • have you tried adding a trailing slash? i.e. `os.path.join('rapports/rapports_journaliers/', filename)` – Timmy O'Mahony Jan 25 '12 at 21:37

0 Answers0