when I do this it just creates a unix executable file of the same name
selected from the drop down menu of users, i.e., if a user named
testuser24 is selected from the user menu and there is a folder named
testuser24 a unix executable is created named testuser24_. Does this
have something to do with the instance parameter?
class Listing(models.Model):
user = models.ForeignKey(User)
name = models.CharField(max_length=50)
order = models.ForeignKey('Order')
def overwrite_upload_to(self, name):
user_dir_path = os.path.join('listings', self.user.username)
return user_dir_path
zipfile = models.FileField(upload_to=overwrite_upload_to)
On Aug 9, 8:35 pm, Karen Tracey <[email protected]> wrote:
> On Sun, Aug 9, 2009 at 10:23 PM, neridaj <[email protected]> wrote:
>
> > It was suggested to me in an earlier post, to override save, and
> > though I've read the documentation for upload_to before I guess I
> > don't quite know how to implement it without an example. Due to my
> > lack of experience I don't know how to address the 'instance' and
> > 'filename' arguments required by the callable, is this even close?
>
> > class Listing(models.Model):
> > user = models.ForeignKey(User)
> > name = models.CharField(max_length=50)
> > order = models.ForeignKey('Order')
>
> > def overwrite_upload_to(self, name):
> > user_dir_path = os.path.join(settings.MEDIA_ROOT, 'listings',
> > self.user.username)
> > return user_dir_path
>
> Don't add in MEDIA_ROOT yourself. The return value from a callable
> upload_to (just as if it were a simple string) is appended to your
> MEDIA_ROOT setting. So you don't need to add it in yourself.
>
>
>
> > zipfile = models.FileField(upload_to=overwrite_upload_to(self,
> > name))
>
> Don't include the parens and parameters. Just pass the callable:
>
> zipfile = models.FileField(upload_to=overwrite_upload_to)
>
> Karen
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---