python - Change the extension of previous uploaded files using Django -


models.py

class entry(models.model):     owner = models.foreignkey(user, related_name='owner')     myfile = models.filefield(upload_to='my_files/%y/%m/%d') 

i need change extension of uploaded files using model.

note upload_to can callable, this:

import date import os def upload_path(instance, filename):     d = date.today()     parts = os.path.splitext(filename)     return 'my_files/%s/%s/%s/%s.%s' % (         d.year, d.month, d.day, parts[0], 'new_ext') 

so, in model:

class entry(models.model):    # ...    myfile = models.filefield(upload_to=upload_path) 

this won't handle files uploaded in past, new uploads have correct names.


Comments

Popular posts from this blog

hibernate - How to load global settings frequently used in application in Java -

python 3.x - Mapping specific letters onto a list of words -

objective c - Ownership modifiers with manual reference counting -