So I've been thinking a lot recently about FileField/UploadField, and
how restricting they are for any app that might want users to upload
files.

Namely, the fact that the upload_to can only use strftime() to vary
the directories.

I did submit a patch (http://code.djangoproject.com/ticket/1994)
awhile ago that lets you specify the directory you want, but only if
you're willing to manually use the save_XXX_file method in your own
custom view.

This means of course that you can't use it with the generic views.

I think a fairly typical use case for a generic view would be an User
Account creation form, for a forum, or some other app. A lot of times,
you want the user to be able to upload an avatar or other files. Or
maybe something like a where users can upload attachments with their
posts.

The way things currently stand, there's no way to give each user their
own directory in the filesystem (unless you use my patch, but it won't
work for generic views).

And even worse, files can get "lost" if they upload two files with the
same name. The old one won't be pointed at in the database anymore,
and the new one will have an "_" at the end of it. Of course, if you
drop to a lower level (and are using my patch), you can  manually
remove the old file, but that doesn't seem very Django-nic (to borrow
a term...)

So what I'm thinking, is to allow something like the following:

class User(models.Model):
    username = models.CharField(...)
    avatar = models.ImageField(upload_to="users/" + self.username,
erase_old=True)

Of course, we can't use 'self' in the field declarations like that,
but I think the idea is clear enough.

And the erase_old=True could mean something like: "If we're updating a
row in the table, delete whatever the old file was"

Does anyone have any good API ideas for this? Am I the only one that
sees the use in it? I'd be willing to try writing the code, but I'd
appreciate some community feedback before getting started.

Thanks,
Jay P.

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

Reply via email to