2009/7/2 Andrew Turner <acturne...@gmail.com>: > Would it be possible to define the hashed filename in the save method, > and then pass it to the upload_to argument of the ImageField?
In answer to my own question, this seems to work:- def get_path(instance, name): return instance._my_filename class Photo(models.Model): photo = models.ImageField(upload_to=get_path, blank=False) ... slug = models.CharField(max_length=16, unique=True) def save(self): name = hashlib.sha1(str(random.random())).hexdigest()[:16] self._my_filename = '%s.jpg' % (name) self.slug = name super(Post, self).save() Cheers, Andrew --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---