I'm a bit confused on a few points here. The upload_to field attribute should be atomic to the imagefield - it doesn't rely on related models.
your change_upload_to creates a new screenshot - but doesn't connect it to the current WebProject instance. Is that what you are trying to do? s = ScreenShot(project=instance) Is there a reason your WebProject is not defined when you create a screenshot in your view? Something about this seems like it is making it more complicated than it needs to be. but details are lacking t -Preston On Nov 24, 5:52 pm, neridaj <neri...@gmail.com> wrote: > Hello, > > I'm trying to change the upload_to attribute of an ImageField so that > it is in the format "web_projects/year/slug/". The problem I am having > is that the ForeignKey model is getting saved before the related > ScreenShot model is able to call it's save method to change upload_to. > I'm trying to use a pre_save signal to reverse the order of saving but > I'm not sure how to access the current instance of the ScreenShot > model to call it's save method. Thanks for any suggestions. > > class ScreenShot(models.Model): > project = models.ForeignKey(WebProject) > image = models.ImageField(upload_to="web_projects/%Y/") > page_title = models.CharField(max_length=250, help_text="Maximum 250 > characters.") > > def __unicode__(self): > return self.page_title > > def save(self): > self.image.upload_to="web_projects/%Y/"+self.project.slug > super(ScreenShot, self).save() > > def change_upload_to(sender, **kwargs): > s = ScreenShot() # not sure how to access current instance > s.save() > > pre_save.connect(change_upload_to, sender=WebProject) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.