On Dec 29, 9:02 pm, garagefan <monkeygar...@gmail.com> wrote: > below is the code... the first def doesn't return anything... (def > get_gal_teaser(self)) > i'm using a custom tag to return the Gallery class to the base > template file, which works... so calling the method get_gal_teaser > works as well... and returns an object? when the second e = > e.image.get_thumbnail_url() is not there... ie this is returned: > [<ImageUpload: image 1>] > > i want to return, obviously from above, the get_thumbnail url method > so i can work with html/css to display it nicely in a secondary nav > > class Gallery(models.Model): > name = models.CharField(max_length=200) > descrip = models.TextField() > gallery_id = models.AutoField(primary_key=True) > > def get_gal_teaser(self): > e = ImageUpload.objects.filter(gallery = self.gallery_id)[:1] > e = e.image.get_thumbnail_url() > return e > > def __unicode__(self): > return u'%s ' %(self.name) > > class ImageUpload(models.Model): > title = models.CharField(max_length=200) > image = models.ImageField(upload_to = 'gallery') > gallery = models.ForeignKey('Gallery') > > def save(self): > super(ImageUpload, self).save() > if self.image: > tsize = 150,150 > path = settings.MEDIA_ROOT + self.image.name > img2 = Image.open(path) > img2.thumbnail(tsize, Image.ANTIALIAS) > img2.save(self.get_thumbnail_path()) > > def get_thumbnail_path(self): > path = settings.MEDIA_ROOT + self.image.name > return self.convert_path_to_thumbnail(path) > > def convert_path_to_thumbnail(self, path): > basedir = os.path.dirname(path) + '/' > base, ext = os.path.splitext(os.path.basename(path)) > th_name = base + "_tn" > th_name += ext > return urlparse.urljoin(basedir,th_name) > > def get_thumbnail_url(self): > path = settings.MEDIA_ROOT + self.image.name
You haven't clearly explained what the problem is, but there are two issues here. Firstly, get_gal_teaser method as written could not work. This slice - [:1] - returns a list containing one item, so at that point e is still a list. So e.image would fail. To make this work as written, just drop the colon. e = ImageUpload.objects.filter(gallery = self.gallery_id)[1] Now e is a single ImageUpload object, and e.image will work. Secondly, the get_thumbnail_url method on ImageUpload does not return anything. You set the variable 'path', but don't return it. Add this: return path at the end. -- DR. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---