On Tue, Aug 4, 2009 at 2:53 PM, caliman<stefanhjel...@gmail.com> wrote: > > 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 needed to do self.the_file. In python member variables aren't automatically accessible, you have to get them from self. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." -- Voltaire "The people's good is the highest law." -- Cicero "Code can always be simpler than you think, but never as simple as you want" -- Me --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---