I have an Image model:

class Image(models.Model):
    photo = ImageWithThumbsField(
            upload_to=image_upload_location,
            sizes=((thumb_widths,thumb_heights),))

The ImageWithThumbsField is something I got from 
http://code.google.com/p/django-thumbs/
It seems to work fine when I have a ModelForm created from the Image
model, but at the moment I'm trying to create a Image object, and save
it - so I do this:

new_image = ImageWithThumbsField(images_to_save[image],
                    upload_to=ListingModels.image_upload_location,
                    sizes=((ListingModels.thumb_widths,
ListingModels.thumb_heights),))
image_object= Image(photo=new_image)
image_object.save()


The ImageWithThumbsField class extends django.db.models.ImageField,
and sets another class 'ImageWithThumbsFieldFile' as the attr_class.

I'm guessing that the attr_class is used when the Model is saved -as
the ImageWithThumbsFieldFile __init__ method is called when the model
is being saved:

class ImageWithThumbsFieldFile(ImageFieldFile):
    """
    See ImageWithThumbsField for usage example
    """
    def __init__(self, *args, **kwargs):
        super(ImageWithThumbsFieldFile, self).__init__(*args,
**kwargs)
        self.sizes = self.field.sizes

        if self.sizes:
            def get_size(self, size):
                if not self:
                    return ''
                else:
                    split = self.url.rsplit('.',1)
                    thumb_url = '%s.%sx%s.%s' % (split[0],w,h,split
[1])
                    return thumb_url

            for size in self.sizes:
                (w,h) = size
                setattr(self, 'url_%sx%s' % (w,h), get_size(self,
size))


The Line that causes the failure is in ImageWithThumbsFieldFile, and
is the  split = self.url.rsplit('.',1) line.

Traceback:
File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py"
in get_response
  86.                 response = callback(request, *callback_args,
**callback_kwargs)
File "/usr/lib/python2.5/site-packages/django/contrib/auth/
decorators.py" in __call__
  67.             return self.view_func(request, *args, **kwargs)
File "/home/louis/uniListings/../uniListings/listings/views.py" in add
  63.                 imageModel.save()
File "/usr/lib/python2.5/site-packages/django/db/models/base.py" in
save
  311.         self.save_base(force_insert=force_insert,
force_update=force_update)
File "/usr/lib/python2.5/site-packages/django/db/models/base.py" in
save_base
  371.                 values = [(f, f.get_db_prep_save(raw and getattr
(self, f.attname) or f.pre_save(self, True))) for f in
meta.local_fields if not isinstance(f, AutoField)]
File "/usr/lib/python2.5/site-packages/django/db/models/fields/
__init__.py" in pre_save
  179.         return getattr(model_instance, self.attname)
File "/usr/lib/python2.5/site-packages/django/db/models/fields/
files.py" in __get__
  122.             instance.__dict__[self.field.name] =
self.field.attr_class(instance, self.field, file)
File "/home/louis/uniListings/listings/thumbs.py" in __init__
  118.                 setattr(self, 'url_%sx%s' % (w,h), get_size
(self, size))
File "/home/louis/uniListings/listings/thumbs.py" in get_size
  112.                     split = self.url.rsplit('.',1)
File "/usr/lib/python2.5/site-packages/django/db/models/fields/
files.py" in _get_url
  54.         return self.storage.url(self.name)
File "/usr/lib/python2.5/site-packages/django/core/files/storage.py"
in url
  213.         return urlparse.urljoin(self.base_url, name).replace('\
\', '/')
File "/usr/lib/python2.5/urlparse.py" in urljoin
  253.             urlparse(url, bscheme, allow_fragments)
File "/usr/lib/python2.5/urlparse.py" in urlparse
  154.     tuple = urlsplit(url, scheme, allow_fragments)
File "/usr/lib/python2.5/urlparse.py" in urlsplit
  193.     i = url.find(':')

Exception Type: AttributeError at /listings/add/
Exception Value: 'ImageWithThumbsField' object has no attribute 'find'


I'm really struggling with this error, if anyone has any ideas, I'll
be glad to hear them :)

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