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

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -