What you have written (this join for user_dir_path) is evaluated only once on model class creation, but what you need is evaluating it for each specific object.
I recommend you overloading the model save method to alter the image save path. On Jul 17, 10:44 am, "neri...@gmail.com" <neri...@gmail.com> wrote: > Hello, > > I'm trying to build a photo upload path which corresponds to the > selected user i.e., when the user is selected from the drop down the > username gets appended to the file upload path dynamically. If you > have any ideas I would like to hear them: > > class Listing(models.Model): > user = models.ForeignKey(User, unique=True) > user_directory_path = os.path.join(settings.MEDIA_ROOT, 'listings', > user) > user_directory = models.FilePathField(path=user_directory_path, > recursive=True) > photo = models.ImageField(upload_to=user_directory) > name = models.CharField(max_length=50) > order = models.ForeignKey('Order') > > def __unicode__(self): > return self.name > > I keep getting this error: > > AttributeError: 'ForeignKey' object has no attribute 'startswith' --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---