On 6/14/06, Ivan Sagalaev <[EMAIL PROTECTED]> wrote: > > Jay Parlar wrote: > > 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) > > > For "upload_to" case I think this will work: > > upload_to="users/%(username)s" > > with a substitution: > > dir = upload_to % obj.__dict__ > > A (little) problem I see with this solution is that data may be not safe > for a filename but Django does some safety replacements for supplied > filenames anyway so it can be used here too. >
Right, I always forget about Python's builtin string templating. That's a neat way to do that. > I like your erase_old. The logic (as I implemented it in my views) can > be as follows: > > old_filename = obj.get_FILED_filename() > <submit new data as usual> > if erase_old and > (<new filename is empty> or <there is a new file content>) and > <old_filename exists>: > os.remove(old_filename) Yep, that's essentially what I was thinking. 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 -~----------~----~----~----~------~----~------~--~---