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