1 2 3 4 5 6 7 8 9 10 11 12 | import os
def slug_filename(path):
""" Returns a callable that can set upload_to to 'path/slug.ext'
i is a (model) instance (with a field called 'slug'), f is a filename.
>>> upload_to = slug_filename(u"/my/path/")
>>> test_model_instance = type("",(),dict(slug=u"slugy"))()
>>> upload_to(test_model_instance, u"myfilename.jpg")
u"/my/path/slugy.jpg"
"""
return lambda i,f: os.path.join(path, u''.join((i.slug, os.path.splitext(f)[1])))
|
More like this
- Use the primary key in FileField and ImageField filenames by exogen 3 years, 4 months ago
- Dynamic thumbnail generator by semente 3 years, 11 months ago
- Easy file upload handler by mattdw 3 years, 5 months ago
- ImageWithThumbsField by zenx 3 years, 1 month ago
- YAAS (Yet Another Auto Slug) by carljm 3 years, 8 months ago
Comments