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):
class Song(models.Model): album = models.CharField(maxlength=255) title = models.CharField(maxlength=255) artist = models.CharField(maxlength=255) track = models.PositiveSmallIntegerField() year = models.PositiveIntegerField() genre = models.CharField(maxlength=40) 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: * Many (though I expect not all) will believe that the filename would update automatically when the model itself is updated. This is obviously not the case, and the documentation would try to make this clear, but it's a whole round of questions I expect to hear anyway. * An often-requested variant on this scheme is the ability to determine subdirectories based on instance data as well. For instance: ..., filename='%(genre)s/%(year)s/%(artist)s/%(album)s_%(track)s_%(title)s.mp3' Currently, get_filename uses os.path.basename, and after filestorage goes in, get_available_filename will do the same. This means that any directory information is lost, unless it's preserved separately. It's possible, but will take a bit of doing. Frankly, I'm not sure it's worth it, given the above concerns, but since working with filestorage, I've been paying attention to FileField gripes, and this comes up more often than anything else I've seen. Do you guys think this is worth implementing? It wouldn't be part of filestorage itself, but how it gets implemented will depend a bit on when filestorage makes it into trunk. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---