Created
January 8, 2012 06:27
-
-
Save amites/1577472 to your computer and use it in GitHub Desktop.
Django TemplateTag to Return Filename without Directory Information
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import template | |
register = template.Library() | |
@register.filter | |
def fileNameClean(file, arg): | |
''' | |
Return the file name without any directory information. | |
''' | |
obj = getattr(file, arg, False) | |
if obj: | |
return obj.name[len(file._meta.get_field(arg).upload_to) + 1:] | |
else: | |
return file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment