Opened 18 years ago

Closed 18 years ago

Last modified 18 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: dev
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

Description

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@…> 18 years ago.
simple patch for latest svn trunk

Download all attachments as: .zip

Change History (5)

by Herbert Poul <herbert.poul@…>, 18 years ago

simple patch for latest svn trunk

comment:1 by Chris Beaven, 18 years ago

Triage Stage: UnreviewedReady for checkin

Simple and useful.

comment:2 by Jacob, 18 years ago

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 by Herbert Poul <herbert.poul@…>, 18 years ago

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 by Chris Beaven, 18 years ago

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

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