Hi!

I'm trying to change upload_to dynamically.

My model:
class File(models.Model):
    type = models.CharField(max_length=10)
    the_file = models.FileField(upload_to="folder")
def __unicode__(self):
        return self.file.name

Tried following:

1, overwrite upload_to in save:
def save(self, force_insert=False, force_update=False):
        the_file.upload = "new_folder"
        super(File, self).save(force_insert, force_update)

This gives:
Exception Type:         NameError
Exception Value:        global name 'the_file' is not defined

Also tried with slug fields and setting a function and set value in
runtime with:
the_file = models.FileField(upload_to=get_path)

that works great if I just want to change the filename but I can't
change folder.

So what am I doing wrong?

Stefan





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

Reply via email to