Am Dienstag, 23. Oktober 2007 14:49 schrieb Marty Alchin:
> 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.

Hi,

I am one of the people who asked for this. I only want to use the 
primary key for a directory name. I think a filename is not enough:
I don't want to store the files under MEDIA_ROOT. Otherwise you can't
use access control, since the request gets served by apache/lighttpd, not
django.

Example: if an Object class should have N attachments:

class Object(models.Model):
    pass

class Attachment(models.Model):
    object=models.ForeignKey(Object)
    filename=models.FileField()

The file should be saved under /non-public-path/attachments/OBJECT_ID/

For me, it's enough to store the basename in the database. The
leading directory (/non-puglic-path/attachments) could be stored in the
models.py file as keyword argument:

    filename=models.FileField(media_root="/...")

The idea of Robert Coup to use a callback looks good. Nevertheless, using
anything other than a primary key is most of the time nonsense, since 
attribute can change, but the physical filename does not (except you have a 
script which updates the filesystem).

> 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.

Please announce it here, if you update your patches. I will try them.
Or send a email to [EMAIL PROTECTED]

 Thomas


--~--~---------~--~----~------------~-------~--~----~
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