Hello,

I'm having trouble overriding save() to change the upload_to attribute
of a FileField object. I would like the upload_to attribute to change
depending on which user is selected from the select menu i.e., if user
testuser24 is selected the upload_to would change to
upload_to='listings/testuser24/'.



class Listing(models.Model):
    user = models.ForeignKey(User)
    zipfile = models.FileField(upload_to='listings')
    name = models.CharField(max_length=50)
    order = models.ForeignKey('Order')

    def overwrite_upload_to(self):
        user_dir_path = os.path.join(settings.MEDIA_ROOT, 'listings',
self.user.username)
        self.zipfile.upload_to=user_dir_path

    def save(self, force_insert=False, force_update=False):
        Listing.overwrite_upload_to(self)
        super(Listing, self).save(force_insert, force_update) # Call
the "real" save() method.

    def __unicode__(self):
                return self.name


Thanks for any help,

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