Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#3538 closed (wontfix)

[Patch] Add get_FOO_basename() for FileFields

Reported by: Herbert Poul <herbert.poul@…> Owned by: Adrian Holovaty
Component: Core (Other) Version: master
Severity: Keywords: filefield basename filename
Cc: herbert.poul@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


It is currently only possible to retrieve absolute pathname or URL of an uploaded file, but not it's basename..(ie. bare filename without any path) - imho this is a very common need.. and i checked dozend of times before believing that it's not already there (i hope i didn't miss it though ;) )

this patch adds a get_FOO_basename() which looks exactly like the existing get_FOO_url() and get_FOO_filename() methods .. and returns only the bare filename.

Attachments (1)

filefield_basename_trunk.diff (1.4 KB) - added by Herbert Poul <herbert.poul@…> 12 years ago.
simple patch for latest svn trunk

Download all attachments as: .zip

Change History (5)

Changed 12 years ago by Herbert Poul <herbert.poul@…>

simple patch for latest svn trunk

comment:1 Changed 12 years ago by Chris Beaven

Triage Stage: UnreviewedReady for checkin

Simple and useful.

comment:2 Changed 12 years ago by Jacob

Resolution: wontfix
Status: newclosed

This is just sugar for os.path.basename(obj.get_FOO_filename()), and so it's a bit too feature-creepy for me. Just use os.path (or, better yet, a path module like Unipath).

comment:3 Changed 12 years ago by Herbert Poul <herbert.poul@…>

imho... if you have a model with a fileupload .. it makes most sense to display the filename in a template..
you will never need the full path or path relative to MEDIA_ROOT ..

so .. i think basename is more useful than the current 'filename' .. because if i ever need 'filename' it's in a view where i can use python code like os.path .. while in a template where i want to output a file's name i need the basename..

of course.. i could simply write a custom method for my model or a template filter.. but i think outputting the name of an uploaded file is somewhat the basic functionality for a fileupload ?

it would be nice if you could rethink this.. it's just 2 lines of code.. but anyway .. maybe i'm missing some important point here.. so i leave the ticket closed ..

comment:4 Changed 12 years ago by Chris Beaven

Herbert, want to bring this up in the Django developers group?

Note: See TracTickets for help on using tickets.
Back to Top