On 23/10/2007, Marty Alchin <[EMAIL PROTECTED]> wrote:
>
> In response to some recent questions regarding FileField usage, I
> thought about including a way to format the filename based on details
> from the model instance itself. It's looking like it' be best to add
> an argument to FileField, called 'filename' perhaps, which takes a
> format string, like so (pardon the inevitable line munging):

...
>     file = models.FileField(upload_to='songs',
> filename='%(album)s_%(track)s_%(title)s.mp3')
>
> However, this raises two concerns, both stemming from the fact that
> given people a cookie will make them want a glass of milk:

Why not allow passing a callable that can do whatever it likes? Then
if they want milk they can write it themselves....

file = models.FileField(upload_to='songs', filename=mysuperfilenamefunc)

def mysuperfilenamefunc(model):
  return "%(album)s_%(track)s_%(title)s.mp3" % model.__dict__

Rob :)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to