On Thu, Jul 23, 2009 at 5:55 PM, Joshua Russo<josh.r.ru...@gmail.com> wrote:
> On Thu, Jul 23, 2009 at 9:31 PM, Rusty Greer <gr...@greer.org> wrote:
>>
>> how do i create a query on the size of an image?
>>
>> for example:
>> class Image(models.Model):
>>
>>    image = models.ImageField(upload_to=upload_to('images'), db_index=True)
>>
>>
>> if i try something like:
>>
>>    for image in Image.objects.filter(image__height_field__gte=100):
>>          # do something
>>
>> i get the following error:
>>
>> django.core.exceptions.FieldError: Join on field 'image' not permitted.
>
> The filters are translated into SQL for the database and the database
> doesn't have a mechanism for reading the image properties. As far as the db
> is concerned it's just another binary field. What I would recommend is to
> create columns for extra information like height and width. Then you can
> override your Image model's save method and extract information and save it
> into the column automatically.
> class Image(models.Model):
>    image = models.ImageField(upload_to=upload_to('images'), db_index=True)
>    height = models.IntegerField()
>    width = models.IntegerField()
>    def save(self, force_insert=False, force_update=False):
>         # The following is sudo code, I have no experience with image
> objects
>         self.height = self.image.height
>         self.width = self.image.width
>         super(Image, self).save(force_insert, force_update) # Call the
> "real" save() method.
> You can read more about models and all the cool stuff  you can do with them
> here: http://docs.djangoproject.com/en/dev/topics/db/models/#topics-db-models
>
>

ok, i have done this.  it seems simple enough.

now i have another issue.  i have a script that imports a few hundred
images into my db.  when i run the script at some point, i get to the
point where i get the following error:

IOError: [Errno 24] Too many open files:
u'/Users/greer/projects/django/static/demo/logos/logo_signs_stars_only_sm0028.png'

from what i can tell, get_image_dimensions in
django/core/files/images.py seems to open the files but never closes
them.  is this a bug?

thanks for any help.

rusty greer

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