Re: ImageField always calling update_dimensions_fields

2016-12-04 Thread ggilley
What I see is that when I load my page, it calls update_dimension_fields 
for every image. The model is simple.


class Photo(models.Model):
width = models.PositiveIntegerField(blank=True, null=True, editable=False, 
default="0")
height = models.PositiveIntegerField(blank=True, null=True, editable=False, 
default="0")
image = ImageField(upload_to=upload_to, width_field='width', 
height_field='height')
user = models.ForeignKey(settings.AUTH_USER_MODEL, 
related_name="uploaded_photos")
title = models.CharField(max_length=255)
slug = extension_fields.AutoSlugField(populate_from='title', blank=True)
caption = models.CharField(max_length=255, blank=True)
date_added = models.DateTimeField(default=timezone.now)


class PhotoCollection(models.Model):
name = models.CharField('name', max_length=250)
slug = extension_fields.AutoSlugField(populate_from='name', blank=True)
description = models.TextField(blank=True)
user = models.ForeignKey(settings.AUTH_USER_MODEL, 
related_name="uploaded_collections")
date_added = models.DateTimeField(default=timezone.now)
photos = models.ManyToManyField('photos.Photo', related_name='collections', 
blank=True)


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/58bb16f7-c162-49da-8226-e388bce588ae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ImageField always calling update_dimensions_fields

2016-12-04 Thread Daniel Roseman
On Sunday, 4 December 2016 00:47:06 UTC, ggi...@gmail.com wrote:
>
>
> I needed to get to the width and height of an image. After discovering 
> that doing so on an ImageField loads the file, I added width_field and 
> height_field to my model.
>
> I did a migration and starting using the new model.
>
> However, it *always* seems to call update_dimension_fields every time the 
> model is loaded.
>
> I'm on 1.9.9 if that makes a difference.
>
> I see there was an old bug where this was addressed 
> https://code.djangoproject.com/ticket/11084
>
> It seems to be broken for me. Any ideas what is going on?
>
> Thanks,
>
>   Greg
>
>
You need to show your model code.
--
DR. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d4c6723a-cbd0-4d48-80d1-aa67116aa830%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ImageField isn't working

2015-02-19 Thread Valéria Pacheco
Thank you very much!
it worked!
Both solutions combined.
I'm still trying to understand what happened but thank you!! :)

2015-02-19 16:18 GMT+00:00 Tom Lockhart :

> On Feb 19, 2015, at 8:03 AM, Valéria Pacheco 
> wrote:
>
> Hello! I'm a newbie in Django and Python, I'm trying to use the ImageField
> property.
> The problem is represented in the attachment images.
> The uploading of the image works fine, but when trying to access it, the
> link seems to be broken.
> I already checked for answers online but neither seems to work.
>
>
> The URL you are trying seems to be
> /admin/backOffice/product/12/media/images/teste_processo.jpg/ which is not
> likely to work.
>
> In my development server settings.py I’ve got the following:
>
> MEDIA_URL = "/media/"
> MEDIA_ROOT = os.path.join(PROJECT_ROOT, *MEDIA_URL.strip("/").split("/"))
>
> and I’ve made a media/ directory inside my project area. Then you can find
> the image with a URL something like:
>
> /media/images/teste_processo.jpg
>
> (which may already be the case for you; look for the uploaded file and use
> a URL prefixed with “/media” then the path to the file).
>
> hth
>
> - Tom
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8cf5041c-2ad7-40ec-9243-d4e1a928013e%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
> 
>
>
>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/Px6Iqhl-ge8/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/F7228E20-08EF-4841-BFF2-AD5FA064CF82%40gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Cumprimentos,
Valéria Pacheco

*contacto móvel *: 913473039



*:)*

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMbyHecNqF7Ra3yFGjscnbFPZmVtmqWbLNNjjruCDUOzTVsb4A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: ImageField isn't working

2015-02-19 Thread Tom Lockhart
On Feb 19, 2015, at 8:03 AM, Valéria Pacheco  wrote:

> Hello! I'm a newbie in Django and Python, I'm trying to use the ImageField 
> property.
> The problem is represented in the attachment images.
> The uploading of the image works fine, but when trying to access it, the link 
> seems to be broken. 
> I already checked for answers online but neither seems to work.

The URL you are trying seems to be 
/admin/backOffice/product/12/media/images/teste_processo.jpg/ which is not 
likely to work.

In my development server settings.py I’ve got the following:

MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(PROJECT_ROOT, *MEDIA_URL.strip("/").split("/"))

and I’ve made a media/ directory inside my project area. Then you can find the 
image with a URL something like:

/media/images/teste_processo.jpg

(which may already be the case for you; look for the uploaded file and use a 
URL prefixed with “/media” then the path to the file).

hth

- Tom


> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/8cf5041c-2ad7-40ec-9243-d4e1a928013e%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
> 


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/F7228E20-08EF-4841-BFF2-AD5FA064CF82%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: ImageField isn't working

2015-02-19 Thread Jorge Andrés Vergara Ebratt
Hello Valéria,

That's Django's default, it doesn't handle media files by itself, if you
are in development you can add this line to urls.py

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Don't forget you need to import static and settings:

from django.conf import settings
from django.conf.urls.static import static

That should work... For development only, in production use something like
Nginx or Apache



On Thu Feb 19 2015 at 11:03:32 AM Valéria Pacheco <
valeriacspach...@gmail.com> wrote:

> Hello! I'm a newbie in Django and Python, I'm trying to use the ImageField
> property.
> The problem is represented in the attachment images.
> The uploading of the image works fine, but when trying to access it, the
> link seems to be broken.
> I already checked for answers online but neither seems to work.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8cf5041c-2ad7-40ec-9243-d4e1a928013e%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAAeX05ErbyhORMmF87xZhRySkN7QHb3gzYT1u7x%3D9mDx27AS3w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: ImageField isn't working

2015-02-19 Thread Lucas Klassmann
Hi Valéria,

Try verify if that support for statics files is correctly configured.

Check this: https://docs.djangoproject.com/en/1.7/howto/static-files/

Before read the documentation, check which version of your django is
installed.

Cheers.

On Thu, Feb 19, 2015 at 2:03 PM, Valéria Pacheco  wrote:

> Hello! I'm a newbie in Django and Python, I'm trying to use the ImageField
> property.
> The problem is represented in the attachment images.
> The uploading of the image works fine, but when trying to access it, the
> link seems to be broken.
> I already checked for answers online but neither seems to work.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8cf5041c-2ad7-40ec-9243-d4e1a928013e%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Lucas Klassmann
Desenvolvedor de Software

Email: lucasklassm...@gmail.com
Web site: http://www.lucasklassmann.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOz50pJCcFxB-eA31hvzsGHiXcUSfof9OUwVV_USo8WTicb0Ew%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: ImageField upload_to issue

2013-01-26 Thread Sammael
I'm terribly sorry, my bad. Of course, the second example is:

class Image(models.Model):
image = models.ImageField(upload_to = upload_path('i'), blank=True)
thumbnail = models.ImageField(upload_to = upload_path('t'), blank=True)


суббота, 26 января 2013 г., 3:58:55 UTC+4 пользователь leonardo написал:
>
> There is no t_upload_path
>
>
> 2013/1/25 Sammael 
>
>> Hello, folks!
>>
>> Here is the relevant part of my model:
>>
>> def i_upload_to(instance, filename):
>> return '/'.join([strftime('i/%y%m/%d'), filename])
>>
>> def t_upload_to(instance, filename):
>> return '/'.join([strftime('t/%y%m/%d'), filename])
>>
>> class Image(models.Model):
>> image = models.ImageField(upload_to=i_upload_to, blank=True)
>> thumbnail = models.ImageField(upload_to=t_upload_to, blank=True)
>>
>>
>> It works as expected, but it's really ugly, terrible code. Let's try to make 
>> it a little better:
>>
>> def upload_path(p):
>> return lambda instance, filename: '/'.join([p, strftime('%y%m/%d'), 
>> filename])
>>
>>
>> class Image(models.Model):
>> image = models.ImageField(upload_to=upload_path('i'), blank=True)
>> thumbnail = models.ImageField(upload_to=t_upload_path('t'), 
>> blank=True)
>>
>>
>> In this case 'image' will be uploaded where expected (e.g. 'i/1301/26'), 
>> but thumbnail will be uploaded to directory like 't/1301/25/i/1301/26/' 
>> instead of 't/1301/26'.
>>
>> Any opinions? Where do I make a mistake?
>>
>> Thank you in advance for any advice.
>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To post to this group, send email to django...@googlegroups.com
>> .
>> To unsubscribe from this group, send email to 
>> django-users...@googlegroups.com .
>> Visit this group at http://groups.google.com/group/django-users?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>

-- 
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.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: ImageField upload_to issue

2013-01-25 Thread Leonardo S
There is no t_upload_path


2013/1/25 Sammael 

> Hello, folks!
>
> Here is the relevant part of my model:
>
> def i_upload_to(instance, filename):
> return '/'.join([strftime('i/%y%m/%d'), filename])
>
> def t_upload_to(instance, filename):
> return '/'.join([strftime('t/%y%m/%d'), filename])
>
> class Image(models.Model):
> image = models.ImageField(upload_to=i_upload_to, blank=True)
> thumbnail = models.ImageField(upload_to=t_upload_to, blank=True)
>
>
> It works as expected, but it's really ugly, terrible code. Let's try to make 
> it a little better:
>
> def upload_path(p):
> return lambda instance, filename: '/'.join([p, strftime('%y%m/%d'), 
> filename])
>
>
> class Image(models.Model):
> image = models.ImageField(upload_to=upload_path('i'), blank=True)
> thumbnail = models.ImageField(upload_to=t_upload_path('t'), 
> blank=True)
>
>
> In this case 'image' will be uploaded where expected (e.g. 'i/1301/26'),
> but thumbnail will be uploaded to directory like 't/1301/25/i/1301/26/'
> instead of 't/1301/26'.
>
> Any opinions? Where do I make a mistake?
>
> Thank you in advance for any advice.
>
>  --
> 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.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: ImageField in admin always required

2012-12-16 Thread Detectedstealth
Thanks required=False is what I needed :). 

"ImageField is not required as expected" Isn't that what you want? :) Yes 
that is exactly what I wanted but also wanted to display the actual  
setting the required=False allows me to have my cake and eat it too :). Not 
sure why required vs blank, null slipped my mind.

PS: It gives great JOY :D

On Wednesday, December 12, 2012 1:39:36 PM UTC-8, Chris Cogdon wrote:
>
>
>
> NOTE: I tried adding null=True, blank=True to forms.ImageField however I 
>> get errors __init__() got an unexpected keyword argument so I guess I can't 
>> use them options. If I comment out the def formfield_for_dbfield(self, 
>> db_field, **kwargs): then the ImageField is not required as expected.
>>
>
> "ImageField is not required as expected" Isn't that what you want? :)
>
> Anyway, the attribute for allowing a FormField to be "left blank" is 
> required=False... blank=True and null=True are for ModelFields
>
> If that knowledge doesn't give you any joy, try constructing a simple 
> model that is not inherited from AbstractBaseUser... does that still end up 
> having the picture be required?
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/csQYMquCKr0J.
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.



Re: ImageField in admin always required

2012-12-12 Thread Chris Cogdon


NOTE: I tried adding null=True, blank=True to forms.ImageField however I 
> get errors __init__() got an unexpected keyword argument so I guess I can't 
> use them options. If I comment out the def formfield_for_dbfield(self, 
> db_field, **kwargs): then the ImageField is not required as expected.
>

"ImageField is not required as expected" Isn't that what you want? :)

Anyway, the attribute for allowing a FormField to be "left blank" is 
required=False... blank=True and null=True are for ModelFields

If that knowledge doesn't give you any joy, try constructing a simple model 
that is not inherited from AbstractBaseUser... does that still end up 
having the picture be required?


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/zVyTxggDEdkJ.
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.



Re: ImageField in admin always required

2012-12-12 Thread Detectedstealth
Update:

Looks like it was an issue with the admin.py file custom code, I was 
following a code sample to display images inline which is causing the field 
to become required. Any suggestions on how to fix this? (See code below) 

class AdminImageFieldWithThumbWidget(forms.widgets.FileInput):

  def __init__(self, thumb_width=50, thumb_height=50):

self.width = thumb_width

self.height = thumb_height

super(AdminImageFieldWithThumbWidget, self).__init__({})


  def render(self, name, value, attrs=None):

thumb_html = ''

if value and hasattr(value, 'url'):

  print(value)

  thumb_html = '' % 
(value.url, self.width, self.height)

return mark_safe("%s%s" % (thumb_html, 
super(AdminImageFieldWithThumbWidget, self).render(name, value, attrs)))


class CustomUserAdmin(UserAdmin):

  def formfield_for_dbfield(self, db_field, **kwargs):

if db_field.name == 'picture':

  returnforms.ImageField(widget=AdminImageFieldWithThumbWidget(thumb_width 
= 
self.thumb_width, thumb_height = self.thumb_height))

return super(CustomUserAdmin,self).formfield_for_dbfield(db_field, 
**kwargs)

NOTE: I tried adding null=True, blank=True to forms.ImageField however I 
get errors __init__() got an unexpected keyword argument so I guess I can't 
use them options. If I comment out the def formfield_for_dbfield(self, 
db_field, **kwargs): then the ImageField is not required as expected.

On Thursday, December 6, 2012 2:47:57 PM UTC-8, Detectedstealth wrote:
>
> Hi,
>
> I have a picture for my custom user declared as follows:
>
> class CustomUser(AbstractBaseUser):
> picture = models.ImageField(upload_to='profile_pictures', null=True, 
> blank=True)
>
> In admin I use the image
>
> class CustomUserAdmin(UserAdmin):
> fieldsets(
> ('Profile details', {
> 'fields': (
> 'picture',
> 'status',
> )
> }),
> )
>
> Now for some reason even though I have null=True, blank=True in admin the 
> picture turns into a required field. Has anyone else experienced this or is 
> this expected behaviour ? 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/PlWOa--L5TAJ.
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.



Re: [ImageField -Upload a valid image]

2012-08-20 Thread Thomas Orozco
I'd you believe PIL is not picking up your libjpeg when it should be, you
could give Pillow a shot ; its basically a PIL installer that makes
installation easier.
Le 20 août 2012 22:30, "Kurtis Mullins"  a écrit :

> Whenever you compile PIL, make sure that libjpeg is available to it. You
> should see a message showing you what is available when you install PIL.
>
> On Mon, Aug 20, 2012 at 3:33 PM, MN TS  wrote:
>
>> Yes.
>>
>> Png and GIF are ok.
>>
>>
>> On Mon, Aug 20, 2012 at 8:00 PM, Amyth Arora 
>> wrote:
>>
>>> did you try uploading any other images ?
>>>
>>>
>>> On Mon, Aug 20, 2012 at 12:58 AM, MN TS  wrote:
>>> > Hello everybody.
>>> >
>>> > I've problem. When i upload image and submit i got follow form error.
>>> >- Upload a valid image. The file you uploaded was either not an
>>> image or
>>> > a corrupted image.
>>> >
>>> > I reinstall PIL (1.1.7) and setup.py file edit like JPEG_ROOT =
>>> > '/usr/lib/i386-linux-gnu/'.
>>> >
>>> > 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.
>>>
>>>
>>>
>>> --
>>> Thanks & Regards
>>> 
>>>
>>> Amyth [Admin - Techstricks]
>>> Email - aroras.offic...@gmail.com, ad...@techstricks.com
>>> Twitter - @a_myth_
>>> http://techstricks.com/
>>>
>>> --
>>> 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.
>>>
>>>
>>  --
>> 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.
>>
>
>  --
> 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.
>

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



Re: [ImageField -Upload a valid image]

2012-08-20 Thread Kurtis Mullins
Whenever you compile PIL, make sure that libjpeg is available to it. You
should see a message showing you what is available when you install PIL.

On Mon, Aug 20, 2012 at 3:33 PM, MN TS  wrote:

> Yes.
>
> Png and GIF are ok.
>
>
> On Mon, Aug 20, 2012 at 8:00 PM, Amyth Arora wrote:
>
>> did you try uploading any other images ?
>>
>>
>> On Mon, Aug 20, 2012 at 12:58 AM, MN TS  wrote:
>> > Hello everybody.
>> >
>> > I've problem. When i upload image and submit i got follow form error.
>> >- Upload a valid image. The file you uploaded was either not an
>> image or
>> > a corrupted image.
>> >
>> > I reinstall PIL (1.1.7) and setup.py file edit like JPEG_ROOT =
>> > '/usr/lib/i386-linux-gnu/'.
>> >
>> > 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.
>>
>>
>>
>> --
>> Thanks & Regards
>> 
>>
>> Amyth [Admin - Techstricks]
>> Email - aroras.offic...@gmail.com, ad...@techstricks.com
>> Twitter - @a_myth_
>> http://techstricks.com/
>>
>> --
>> 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.
>>
>>
>  --
> 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.
>

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



Re: [ImageField -Upload a valid image]

2012-08-20 Thread MN TS
Yes.

Png and GIF are ok.

On Mon, Aug 20, 2012 at 8:00 PM, Amyth Arora wrote:

> did you try uploading any other images ?
>
>
> On Mon, Aug 20, 2012 at 12:58 AM, MN TS  wrote:
> > Hello everybody.
> >
> > I've problem. When i upload image and submit i got follow form error.
> >- Upload a valid image. The file you uploaded was either not an image
> or
> > a corrupted image.
> >
> > I reinstall PIL (1.1.7) and setup.py file edit like JPEG_ROOT =
> > '/usr/lib/i386-linux-gnu/'.
> >
> > 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.
>
>
>
> --
> Thanks & Regards
> 
>
> Amyth [Admin - Techstricks]
> Email - aroras.offic...@gmail.com, ad...@techstricks.com
> Twitter - @a_myth_
> http://techstricks.com/
>
> --
> 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.
>
>

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



Re: [ImageField -Upload a valid image]

2012-08-20 Thread Amyth Arora
did you try uploading any other images ?


On Mon, Aug 20, 2012 at 12:58 AM, MN TS  wrote:
> Hello everybody.
>
> I've problem. When i upload image and submit i got follow form error.
>- Upload a valid image. The file you uploaded was either not an image or
> a corrupted image.
>
> I reinstall PIL (1.1.7) and setup.py file edit like JPEG_ROOT =
> '/usr/lib/i386-linux-gnu/'.
>
> 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.



-- 
Thanks & Regards


Amyth [Admin - Techstricks]
Email - aroras.offic...@gmail.com, ad...@techstricks.com
Twitter - @a_myth_
http://techstricks.com/

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



Re: ImageField filename

2012-01-27 Thread Damian Soriano (Gmail)
You can define a function that returns the path to upload the image, in
this function you receive as argument the object being saved (instance) and
the name of the file (filename). You can return whatever you want as a path
(that include the filename)

def upload_path(instance, filename):
return 'category/' + str(instance.name) + '/image/' + filename

class Category(models.Model):
name = models.CharField(_('name'), max_length=200, unique=True)
image = models.ImageField(_('image'), upload_to=upload_path, blank=True)

BR

Damián

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



Re: ImageField filename

2012-01-27 Thread wayne

This is the same as the FileField. The UploadedFile class has a name
property, which can be used..

https://docs.djangoproject.com/en/dev/topics/http/file-uploads/#handling-uploaded-files



On Jan 19, 9:56 am, Mike Dewhirst  wrote:
> How do I get the actual filename of the uploaded image?
>
> The docs mention ...
>
> FileField.upload_to
> A local filesystem path that will be appended to your MEDIA_ROOT setting
> to determine the value of the url attribute.
>
> ... and presumably the widget which uploads the image knows the filename
> to tack onto the end of upload_to when the webserver gets the request to
> store the image.
>
> But how can I get access to that filename in the model so I can parse it
> and give it a meaningful (to humans) name when being saved?
>
> The docs go on to mention upload_to as a callable but I'm sticking to a
> fixed directory in MEDIA_ROOT for these images.
>
> Thanks for any hints
>
> Mike

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



Re: imagefield problem .....

2011-06-13 Thread Ivo Brodien
> On Jun 13, 2011, at 5:57 PM, Pankaj Singh wrote:
> 
>> yes even in get_image_url it will be
>> 
>> return os.path.join(settings.MEDIA_URL, 'news', 
>> self.image.name.split('/')[-1])

> 


writing that function is not necessary.

from: https://docs.djangoproject.com/en/dev/ref/models/fields/#filefield

> 3) All that will be stored in your database is a path to the file (relative 
> to MEDIA_ROOT). You'll most likely want to use the convenience url function 
> provided by Django. For example, if your ImageField is called mug_shot, you 
> can get the absolute path to your image in a template with {{ 
> object.mug_shot.url }}.


so the Pulkit was trying in his template is ok, he just should use the url 
function and the MEDIA_URL

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



Re: imagefield problem .....

2011-06-13 Thread Pankaj Singh
yes even in get_image_url it will be

return os.path.join(settings.MEDIA_URL, 'news', 
self.image.name.split('/')[-1])

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/JBSPTQLVtWcJ.
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.



Re: imagefield problem .....

2011-06-13 Thread Ivo Brodien

On Jun 13, 2011, at 12:52 PM, Pulkit Mehrotra wrote:

> problem in using the address stored in imagefield

you should describe your problem a little better!

But I guess the URL is not working?

You shouldn’t use STATIC_URL but MEDIA_URL for the prefix in your template.

STATIC_URL is for static files, that don’t change like CSS and JS.

MEDIA_URL is for user uploads, like a photo in your news entry.

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



Re: ImageField issue

2011-06-08 Thread Greg Donald
On Wed, Jun 8, 2011 at 2:51 PM, Daniel Roseman  wrote:
> But that "bunch of image data" is a string - because that's what .read()
> returns.
> The FileField documentation [1] shows how to save a disk file to a field:
>     from django.core.files import File
>     f = open('/tmp/hello.world')
>     myfile = File(f)
>     et.image.save( image_name, myfile )
>
> https://docs.djangoproject.com/en/1.3/ref/models/fields/#django.db.models.FieldFile.save


I see now.. got it working.

Thanks.


-- 
Greg Donald
destiney.com | gregdonald.com

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



Re: ImageField issue

2011-06-08 Thread Daniel Roseman
On Wednesday, 8 June 2011 20:40:35 UTC+1, Greg Donald wrote:
>
> I have a model EventType that has an ImageField named image.
>
> When I post my image upload form I can upload an image with no problems.
>
>
> But when I try to save() an image from the file system I get the error:
>
> 'str' object has no attribute 'chunks'
>
>
> Here is my code:
>
> et = EventType( name=name )
> et.save()
>
> image_name = "%s.png" % name
> image_path = "%s/images/%s.png" % ( settings.MEDIA_ROOT, name )
> image_file = open( image_path, 'rb' )
>
> et.image.save( image_name, image_file.read() )
>
>
> I'm sure the file exists and is readable.
>
> I'm not sure why image_file.read() is returning a str, it spews a
> bunch of what appears to be image data when I debug it.
>
> Any idea what I'm doing wrong?
>
>
> Thanks.
>
 
But that "bunch of image data" is a string - because that's what .read() 
returns. 

The FileField documentation [1] shows how to save a disk file to a field:

from django.core.files import File
f = open('/tmp/hello.world')
myfile = File(f)
et.image.save( image_name, myfile )

https://docs.djangoproject.com/en/1.3/ref/models/fields/#django.db.models.FieldFile.save
--
DR.

>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/QnhPeHYwUkp3QXdK.
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.



Re: imagefield upload_to

2011-05-11 Thread Brian Craft
solved this by moving it to the model clean() method, and using
imagefield.file.open() and imagefield.file.read() to get the data for
computing the other fields.

On Wed, May 11, 2011 at 1:28 PM, Brian Craft  wrote:
> I have a model with an imagefield, and some fields that are computed
> from the image. I'm trying to override the "save" method to fill in
> the other fields.
>
> When I test this in the admin, there are two problems: first, the path
> (mymodel.image.path) doesn't honor the upload_to setting on the field.
> It concats MEDIA_ROOT and the file name, w/o the upload_to. (This is
> django 1.2.3). Second, I don't see the file in the filesystem when
> .save() is called. Perhaps save() is the wrong place to do this?
>
> If I don't try to generated the computed fields, the file is created
> in the correct (upload_to) directory, and if I read the object from
> the db, mymodel.image.path is also correct.
>
> Looks like upload_to is only accessed during FieldFile.save(), where
> the self.name is updated, so the path is always wrong before that.
>
> And apparently the file isn't committed to storage until the field is
> saved. Is there some other way to access the file before it is saved?
>

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



Re: ImageField not deleted while changing

2011-02-27 Thread Artur Wdowiarski
Borislav is right, although it seems to me that overriding the model's save
method would be more appropriate in Your case.

On the other hand, You really should think twice before doing so. There's
actually a good reason for django orm not to delete the actual file after
the corresponding FileField had been changed or deleted. Your models'
edition/deletion is usually handled in db transactions that are rolled back
when something goes wrong and unfortunately there's no way to undo a file's
deletion...

Perhaps it's better to periodically run a script that deletes orphaned
files.

2011/2/27 Borislav Petrović 

> As far as I know, you should implement the file deletion by yourself. You
> should code it on the Models delete function. preserving the default
> behaviour.
> here is a link to some read:
> http://docs.djangoproject.com/en/dev/topics/db/models/#overriding-model-methods
>
> How you do the file deletion is just pure python code further on.
>
>
>
> On Sat, Feb 26, 2011 at 10:12 PM, galago  wrote:
>
>> d. Is it my fault or Django is designed not to delete it (if so, how to
>> delete old fil
>
>
>  --
> 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.
>

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



Re: ImageField not deleted while changing

2011-02-27 Thread Borislav Petrović
As far as I know, you should implement the file deletion by yourself. You
should code it on the Models delete function. preserving the default
behaviour.
here is a link to some read:
http://docs.djangoproject.com/en/dev/topics/db/models/#overriding-model-methods

How you do the file deletion is just pure python code further on.


On Sat, Feb 26, 2011 at 10:12 PM, galago  wrote:

> d. Is it my fault or Django is designed not to delete it (if so, how to
> delete old fil

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



Re: ImageField and built-in filesystem storage

2010-03-02 Thread thanos
You take a look at how I did things in

http://code.google.com/p/django-googledata/

Thanos

On Mar 2, 4:44 am, Xavier Ordoquy  wrote:
> Hi,
>
> I'm currently working on Django for a website on a legacy database but I'm 
> facing an issue on getting ImageField working with it in the admin.
>
> In the database images are stored as a simple file name, because they have 
> several size precomputed on different directories.
> So basically, I need to:
>  - save the filename - and only the filename - the database
>  - save the file to a given location and resize it to different size
>
> I tried different ways to get this working but none did work in order to get 
> the correct filename in the database.
>
> First I edited the ImageField.name when model is saved but the name gets 
> overwritten when saving the model.
>
> Then I gave the build-in filesystem storage but it didn't work 
> better.http://docs.djangoproject.com/en/1.1/topics/files/#the-built-in-files...doesn't
>  mention you need upload_to
> However, whenever upload_to is set, it overrides the storage location which 
> seems to contradict ticket #8918.
>
> Has someone already solved a similar issue ?
>
> Xavier.

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



Re: ImageField admin preview not working

2010-02-28 Thread lockwooddev
(r'^static/(?P.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT}),

the diffirence.

(r'^static_media/(?P.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT}),

Thanks a lot!! :-)
 It cost me one day this tiny problem..

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



Re: ImageField admin preview not working

2010-02-28 Thread Malcolm Box
Read your settings.py file carefully:

- you've said that the MEDIA_URL is /
- but that Django is only configured to serve static content from /static

So when the photo is uploaded, it's stored in /photos/x.jpg,
which you've told Django is accessible via the URL /photos.

But this gives http://example.com/photos

And, as per the error message, Django can't find a matching url pattern for
that.

Cheers,

Malcolm

On Sun, Feb 28, 2010 at 5:57 PM, lockwooddev  wrote:

> Hi people,
>
> I started working on an image gallery with Django and I'm stuck. I
> suppose that my static files on the development server are not
> configured properly.
>
> I have the following models.py code:
>
> from django.db import models
> from PIL import Image
>
>
> class Photo(models.Model):
>name = models.CharField(max_length=100)
>description = models.TextField()
>image = models.ImageField(upload_to='photos')
>
>
> 
>
> My setting.py file:
>
>
> MEDIA_ROOT = '/Users/lockwood/Django-1.1.1/md/static_media/'
> MEDIA_URL = '/'
> ADMIN_MEDIA_PREFIX = '/media/'
>
>
> 
>
> And url.py file:
>
> urlpatterns = patterns('',
>(r'^admin/', include(admin.site.urls)),
>(r'^static/(?P.*)$', 'django.views.static.serve',
>{'document_root': settings.MEDIA_ROOT}),
> )
>
>
> 
>
> When I click on the Photo object in the admin view to preview the
> image i've uploaded, I get the following 404 page:
>
>
> Page not found (404)
> Request Method: GET
> Request URL:
> http://127.0.0.1:8000/photos/1459049280_144e7d874a_o-at-2008-12-06.jpg
>
> Using the URLconf defined in md.urls, Django tried these URL patterns,
> in this order:
>
>   1. ^admin/
>   2. ^static/(?P.*)$
>
> The current URL, photos/1459049280_144e7d874a_o-at-2008-12-06.jpg,
> didn't match any of these.
>
> 
>
> The photo's are stored in the absolute path:
>
> /Users/lockwood/Django-1.1.1/md/static_media/photos/
>
> 
>
> I've tried everything and don't know what to do now?
>
> --
> 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.
>
>

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



Re: ImageField anti-duplication

2009-09-20 Thread A. Rossi

Yup, that did it!
Thanks for pointing that out!  That article was hard to find in the
documentation.


On Sep 12, 7:58 pm, "A. Rossi"  wrote:
> I had not considered writing a custom Storage class. I may try that if
> there are no other alternatives.
>
> Any other ideas/solutions?
>
> On Sep 12, 5:31 am, vinilios  wrote:
>
> > Have you read this ?
>
> >http://docs.djangoproject.com/en/dev/howto/custom-file-storage/
>
> > haven't used any custom file storage yet but maybe using a custom file-
> > storage with a dummy save method when file exists is what you need.
>
> > On Sep 12, 1:43 pm, "A. Rossi"  wrote:
>
> > > I have an application where users can upload images, then the image is
> > > renamed to a SHA256 hash of the file's contents.
> > > Here is the relevant snippet of the model
>
> > > class ImagePost(Post):
> > >     def imgurl(self, filename):
> > >         import hashlib, os.path
> > >         extension = os.path.splitext(filename)
> > >         self.image.seek(0)
> > >         return "images/%s%s" % (hashlib.sha256(self.image.read
> > > (self.image.size)).hexdigest(), extension[1])
>
> > >     image = models.ImageField(upload_to=imgurl, blank=True)
>
> > > what I am attempting to do is, if a user uploads an image that already
> > > exists (i.e. the two files have the exact same SHA256 hash) I want to
> > > have the ImageField point to the already existing file, rather than
> > > save the newly uploaded one. I have tried a couple things that didn't
> > > work, and the default behavior when dealing with files of the same
> > > name is to append an extra _ to the end of the name, before the
> > > extension.
>
> > > I feel like I'm on the cusp of figuring this out, but I'm stuck. Also,
> > > would I put the code for this into the imgurl() function, create a
> > > custom storage object, in the view(s) directly?
>
> > > Thank you for your help.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: ImageField anti-duplication

2009-09-12 Thread A. Rossi

I had not considered writing a custom Storage class. I may try that if
there are no other alternatives.

Any other ideas/solutions?

On Sep 12, 5:31 am, vinilios  wrote:
> Have you read this ?
>
> http://docs.djangoproject.com/en/dev/howto/custom-file-storage/
>
> haven't used any custom file storage yet but maybe using a custom file-
> storage with a dummy save method when file exists is what you need.
>
> On Sep 12, 1:43 pm, "A. Rossi"  wrote:
>
> > I have an application where users can upload images, then the image is
> > renamed to a SHA256 hash of the file's contents.
> > Here is the relevant snippet of the model
>
> > class ImagePost(Post):
> >     def imgurl(self, filename):
> >         import hashlib, os.path
> >         extension = os.path.splitext(filename)
> >         self.image.seek(0)
> >         return "images/%s%s" % (hashlib.sha256(self.image.read
> > (self.image.size)).hexdigest(), extension[1])
>
> >     image = models.ImageField(upload_to=imgurl, blank=True)
>
> > what I am attempting to do is, if a user uploads an image that already
> > exists (i.e. the two files have the exact same SHA256 hash) I want to
> > have the ImageField point to the already existing file, rather than
> > save the newly uploaded one. I have tried a couple things that didn't
> > work, and the default behavior when dealing with files of the same
> > name is to append an extra _ to the end of the name, before the
> > extension.
>
> > I feel like I'm on the cusp of figuring this out, but I'm stuck. Also,
> > would I put the code for this into the imgurl() function, create a
> > custom storage object, in the view(s) directly?
>
> > Thank you for your help.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: ImageField anti-duplication

2009-09-12 Thread vinilios

Have you read this ?

http://docs.djangoproject.com/en/dev/howto/custom-file-storage/

haven't used any custom file storage yet but maybe using a custom file-
storage with a dummy save method when file exists is what you need.


On Sep 12, 1:43 pm, "A. Rossi"  wrote:
> I have an application where users can upload images, then the image is
> renamed to a SHA256 hash of the file's contents.
> Here is the relevant snippet of the model
>
> class ImagePost(Post):
>     def imgurl(self, filename):
>         import hashlib, os.path
>         extension = os.path.splitext(filename)
>         self.image.seek(0)
>         return "images/%s%s" % (hashlib.sha256(self.image.read
> (self.image.size)).hexdigest(), extension[1])
>
>     image = models.ImageField(upload_to=imgurl, blank=True)
>
> what I am attempting to do is, if a user uploads an image that already
> exists (i.e. the two files have the exact same SHA256 hash) I want to
> have the ImageField point to the already existing file, rather than
> save the newly uploaded one. I have tried a couple things that didn't
> work, and the default behavior when dealing with files of the same
> name is to append an extra _ to the end of the name, before the
> extension.
>
> I feel like I'm on the cusp of figuring this out, but I'm stuck. Also,
> would I put the code for this into the imgurl() function, create a
> custom storage object, in the view(s) directly?
>
> Thank you for your help.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Imagefield, PIL and save()

2009-09-03 Thread aa56280

On Sep 3, 5:31 pm, Rob Broadhead  wrote:
> If you are on a Mac there are some issues with the imagelib you will  
> need to fix.

Very interesting. I am on a Mac. So I'll investigate and update.
Thanks, Rob.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Imagefield, PIL and save()

2009-09-03 Thread Rob Broadhead
If you are on a Mac there are some issues with the imagelib you will  
need to fix. Google Mac PIL django and I think you will get three or  
four walk-throughs to fix the problem. I think you can see the error  
when you run the PIL tests, but I went through a lot of iterations  
just fixing that myself so my recollection may be a bit off.

On Sep 3, 2009, at 5:23 PM, aa56280 wrote:

>
> I have an ImageField in a model. I also have a ModelForm for this
> model. I'm overriding save() so that I can take the image that was
> uploaded and make a thumbnail out of it using PIL.
>
> I'm using the simplest of examples just to get started:
>
> ...
> def save(self):
>  from PIL import Image
>
>  im = Image.open(self.logo)  # 'logo' is the image field name
>  im.thumbnail((100,100), Image.ANTIALIAS)
>  im.save('test.png')
>
> No exception, no errors, but neither was a thumbnail created. I keep
> thinking something's going on with the Image.open() method, but I have
> no clue what. Any ideas greatly appreciated.
>
>
> >

Rob Broadhead
robert.broadh...@gmail.com




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



Re: ImageField width_wield

2009-08-29 Thread Léon Dignòn

No, everything is fine. Once you uploaded a file, you can call
image.width and image.height (where image is an instance of Image).
If you are using ModelForms, you can set editable=False as a parameter
for width and height.

image   = models.ImageField(upload_to='images',
height_field='height', width_field='width')
height = models.PositiveSmallIntegerField(editable=False)
width  = models.PositiveSmallIntegerField(editable=False)



On Aug 27, 3:31 am, TheIvIaxx  wrote:
> Assume i have the following:
>
> class Image(models.Model):
>     image = models.ImageField(upload_to="path/to",
> width_field="width", height_field="height"
>
> do i create new Integer fields there for width and height?  With this
> i can do things like:
>
> >>> Image.objects.get(pk=1).image.width
>
> However this is just opening the file with PIL which is slow.  The
> documentation suggestions the width/height will be updated upon save,
> thus being quick :)
>
> class Image(models.Model):
>     image = models.ImageField(upload_to="path/to",
> width_field="width", height_field="height"
>     width = models.IntegerField()
>     height = models.IntegerField()
>
> did not seem to do anything.  Am i missing something?
>
> 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
-~--~~~~--~~--~--~---



Re: ImageField woes

2009-08-22 Thread Léon Dignòn

If you need it only for one particular form, you can also override
clean_():
---
import Image # PIL

class UserProfileForm(ModelForm):
class Meta:
model = UserProfile

# Model UserProfile has an ImageField named avatar.
def clean_avatar(self):
img = self.cleaned_data['avatar'] # img will be a PIL object
image = Image.open(img)
if image.size[0] > 64: #image.size is a 2-tuple (width,
height)
raise forms.ValidationError("Not more than 64*64 pixels.")
if img.size > 1:
raise forms.ValidationError("Filesize too big. Max. 10k")
#if img.width > 64:

return img
---

You could do all your stuff with the Python Imaging Library in the
clean_... function. I got this hint from another thread:
http://groups.google.com/group/django-users/browse_thread/thread/8ba69b6846e84dd3

I do not know much about the PIL, so maybe it has not the funtionality
you are looking for. Also whether this is worse or better than
creating a custom ImageField, I don't know.

-ld

On Aug 22, 12:03 am, Jon  wrote:
> I want to expand on the ImageField functionality of django. Mainly, I
> want to check the dimensions of the image the user is uploading, and
> resize / crop where appropriate. I would also like to set compression
> amount, and perhaps even allow for watermarking. I know there are
> several libraries out there that do this, but I want to keep it as
> lightweight as possible, and haven't had much luck with sorl.
>
> It seems to me the best way to do this would be to create a custom
> field type, so I could do something like this in my model:
>
> image_tb = models.CustomImageField("Thumbnail Image", upload_to
> ='uploads/projects', size=(50, 50), compression="60", watermark="path/
> to/watermark.png")
>
> Is this the best way to do something like this? I understand that you
> could also hijack the save method, but I might want to have more than
> one image field in each model meaning the sizes might vary. Can anyone
> point me towards any articles which will help me on my way?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: ImageFile bug? (Re: ImageField questions)

2009-07-28 Thread Jacob Kaplan-Moss

On Sun, Jul 26, 2009 at 11:10 PM, Rusty Greer wrote:
> i applied the patch you mentioned before (to my 1.0.2 release):

Yeah, the fix is predicated on some file storage refactoring that's
too intensive to reach the 1.0.X series. You'll need to upgrade to 1.1
to get the fix.

Jacob

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



Re: ImageFile bug? (Re: ImageField questions)

2009-07-27 Thread Rusty Greer

On Sun, Jul 26, 2009 at 10:28 PM, Jacob Kaplan-Moss wrote:
>
> 2009/7/24 Rusty Greer :
>> that bug actually doesn't fix my case.  if i alter the patch to just
>> do a file.close() in all cases, it works.  is there another patch to
>> close the file opened outside of this class?
>
> I'm not sure I follow; let me make sure I understand you:
>
> * You've verified that you're still having problems when running under
> Django 1.1 RC 1?
>
> * If you're opening the image file yourself, you need to make sure you
> also close it. Django can't "guess" whether you want to leave the
> image open or not, so you'll need to make sure any files you open are
> closed.
>
> Jacob
>

it does appear to be fixed  in 1.1 RC 1, i am not opening the file myself

i have a model with an image as you stated before:
> 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.

i applied the patch you mentioned before (to my 1.0.2 release):
> Yes, it was #8817 (http://code.djangoproject.com/ticket/8817) which
> was fixed a few months ago
> (http://code.djangoproject.com/changeset/10708).

after doing this, i am still getting the too many files open error.  i
am not opening the file, it is getting opened in the line "self.height
= self.image.height", change 10708 does not cause the file to be
closed in this case.  i couldn't trace the code the entire way, but a
file object is being passed into get_image_dimensions in this case,
not a path, so the file is not getting opened in this function,
therefore not getting closed in there either.  my question is as
follows:  is there another patch that i can apply to 1.0.2 to fix this
problem?

thanks for all of your help,

rusty

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



Re: ImageFile bug? (Re: ImageField questions)

2009-07-26 Thread Jacob Kaplan-Moss

2009/7/24 Rusty Greer :
> that bug actually doesn't fix my case.  if i alter the patch to just
> do a file.close() in all cases, it works.  is there another patch to
> close the file opened outside of this class?

I'm not sure I follow; let me make sure I understand you:

* You've verified that you're still having problems when running under
Django 1.1 RC 1?

* If you're opening the image file yourself, you need to make sure you
also close it. Django can't "guess" whether you want to leave the
image open or not, so you'll need to make sure any files you open are
closed.

Jacob

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



Re: ImageFile bug? (Re: ImageField questions)

2009-07-24 Thread Jacob Kaplan-Moss

On Fri, Jul 24, 2009 at 8:23 AM, Rusty Greer wrote:
> 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?

Yes, it was #8817 (http://code.djangoproject.com/ticket/8817) which
was fixed a few months ago
(http://code.djangoproject.com/changeset/10708).

So the fix is in the 1.1 release candidate released earlier this week,
and will be in the 1.1 final and also in the next release of the 1.0.X
series.

Jacob

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



ImageFile bug? (Re: ImageField questions)

2009-07-24 Thread Rusty Greer

On Thu, Jul 23, 2009 at 5:55 PM, Joshua Russo wrote:
> On Thu, Jul 23, 2009 at 9:31 PM, Rusty Greer  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
-~--~~~~--~~--~--~---



Re: ImageField questions

2009-07-23 Thread Joshua Russo
On Thu, Jul 23, 2009 at 9:31 PM, Rusty Greer  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*

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



Re: ImageField on ModelForm not working - v1.0.2

2009-03-25 Thread Oli Warner
Well now I feel like a moron! Not only did I forget to pass through
request.FILES, but I needed enctype="multipart/form-data" on my  too.

Thanks to both of you!

/me slaps himself with a hefty dose of RTFM

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



Re: ImageField on ModelForm not working - v1.0.2

2009-03-25 Thread Ayaz Ahmed Khan


On 25-Mar-09, at 5:45 PM, Oli Warner wrote:
>if request.method == 'POST':
>f = AdminEditForm(request.POST.copy(), instance = company)
>if f.is_valid():

Contents of file input fields/objects are stored within request.FILES
dict in Django. You need to add request.FILES as an additional
positional argument to the form constructor.

-- 
Ayaz Ahmed Khan

An evil mind is a great comfort.


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



Re: ImageField on ModelForm not working - v1.0.2

2009-03-25 Thread Alex Koshelev

You don't pass request.FILES to form constructor [1]

[1]: 
http://docs.djangoproject.com/en/dev/ref/forms/api/#binding-uploaded-files-to-a-form


On Wed, Mar 25, 2009 at 3:45 PM, Oli Warner  wrote:
>
> I'm having a massive headache. I have a Model called companies with
> vaious fields but for one form, I want the user to be able to edit two
> ImageFields and a TextField. "Simple", I thought and quickly made a
> ModelForm class:
>
> class AdminEditForm(ModelForm):
>    class Meta:
>        model = Company
>        fields = ['logo', 'intro_pic', 'intro_text']
>
> I hooked it up in this view:
>
> def admin_edit(request, company_slug):
>    company = get_object_or_404(Company, slug = company_slug)
>
>    f = AdminEditForm(instance = company)
>    if request.method == 'POST':
>        f = AdminEditForm(request.POST.copy(), instance = company)
>        if f.is_valid():
>            print "Processing form"
>            print f.cleaned_data['intro_pic']
>            print f.cleaned_data['logo']
>            f.save()
>
>    return render_to_response('uadmin/edit.html', {'company':company,
> 'f':f}, RequestContext(request))
>
>
> Here are the relevant parts of the model definition:
>
> class Company(models.Model):
>    logo = models.ImageField(upload_to='logos', blank=True)
>    intro_pic = models.ImageField(upload_to='intropics', blank=True)
>    intro_text = models.TextField(blank=True)
>
>
> The form *is* working -- it validates and intro_text is saved -- it's
> just the images not saving.
>
> I've hooked out the POST and displayed it on the form and it is
> getting data through from the file inputs:
> QueryDict: {u'logo': [u'oli.png'], u'intro_text': [u'This is some
> text!'], u'intro_pic': [u'oli.png']}
>
> Uploading from the [proper] admin edit form works fine so I don't
> think it's a PIL issue.
>
> Any ideas?
>
> >
>

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



Re: ImageField causing error when rendering with "The Image" attribute has no file associated with it.

2009-02-23 Thread Karen Tracey
On Thu, Feb 19, 2009 at 7:30 AM, mermer  wrote:

>
> Since I've upgraded to Django ver 1.00,  I'm suddenly getting the
> following error with my ImageFields.
>
> The tag is {{ model.image.url}} and it throws an error if the image
> field in the database is null (even if it is set to null in the model)
>
> Am I missing something?  Here is the error message being generated.
>
>
> TemplateSyntaxError at /offer_detail_ver2/1/
>
> Caught an exception while rendering: The 'image' attribute has no file
> associated with it.
>

There was some major file storage refactoring done before 1.0, which I'd
guess introduced a requirement that attempting to retrieve the url
associated with a file-type object requires a file to be associated with
that object.  A little experimenting in the shell shows that now where {{
m.file.url }} generates the exception you report in the case where m.file
has no file,

{% if m.file %}{{ m.file.url }}{% endif %}

does not.  I didn't work on the file storage refactor so I don't know if
this was an intentional difference, and I haven't checked if this was
explicitly documented as a backwards-incompatible change, but it seems
not-so-surprising that such a method would require a file to be set, and
easy enough to adjust to?

Karen

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



Re: ImageField causing error when rendering with "The Image" attribute has no file associated with it.

2009-02-23 Thread mermer

Anybody with any advice on this.  Ever since wev'e upgraded to version
1.00 we are having issues with the ImageField

ValueError: The 'image' attribute has no file associated with it.

On 19 Feb, 12:30, mermer  wrote:
> Since I've upgraded to Django ver 1.00,  I'm suddenly getting the
> following error with my ImageFields.
>
> The tag is {{ model.image.url}} and it throws an error if the image
> field in the database is null (even if it is set to null in the model)
>
> Am I missing something?  Here is the error message being generated.
>
> TemplateSyntaxError at /offer_detail_ver2/1/
>
> Caught an exception while rendering: The 'image' attribute has no file
> associated with it.
>
> Original Traceback (most recent call last):
>   File "C:\Python25\Lib\site-packages\django-trunk\django\template
> \debug.py", line 71, in render_node
>     result = node.render(context)
>   File "C:\Python25\Lib\site-packages\django-trunk\django\template
> \debug.py", line 87, in render
>     output = force_unicode(self.filter_expression.resolve(context))
>   File "C:\Python25\Lib\site-packages\django-trunk\django\template
> \__init__.py", line 535, in resolve
>     obj = self.var.resolve(context)
>   File "C:\Python25\Lib\site-packages\django-trunk\django\template
> \__init__.py", line 676, in resolve
>     value = self._resolve_lookup(context)
>   File "C:\Python25\Lib\site-packages\django-trunk\django\template
> \__init__.py", line 705, in _resolve_lookup
>     current = getattr(current, bit)
>   File "C:\Python25\Lib\site-packages\django-trunk\django\db\models
> \fields\files.py", line 58, in _get_url
>     self._require_file()
>   File "C:\Python25\Lib\site-packages\django-trunk\django\db\models
> \fields\files.py", line 43, in _require_file
>     raise ValueError("The '%s' attribute has no file associated with
> it." % self.field.name)
> ValueError: The 'image' attribute has no file associated with it.
>
> Request Method:         GET
> Request URL:    http://localhost/offer_detail_ver2/1/
> Exception Type:         TemplateSyntaxError
> Exception Value:
>
> Caught an exception while rendering: The 'image' attribute has no file
> associated with it.
>
> Original Traceback (most recent call last):
>   File "C:\Python25\Lib\site-packages\django-trunk\django\template
> \debug.py", line 71, in render_node
>     result = node.render(context)
>   File "C:\Python25\Lib\site-packages\django-trunk\django\template
> \debug.py", line 87, in render
>     output = force_unicode(self.filter_expression.resolve(context))
>   File "C:\Python25\Lib\site-packages\django-trunk\django\template
> \__init__.py", line 535, in resolve
>     obj = self.var.resolve(context)
>   File "C:\Python25\Lib\site-packages\django-trunk\django\template
> \__init__.py", line 676, in resolve
>     value = self._resolve_lookup(context)
>   File "C:\Python25\Lib\site-packages\django-trunk\django\template
> \__init__.py", line 705, in _resolve_lookup
>     current = getattr(current, bit)
>   File "C:\Python25\Lib\site-packages\django-trunk\django\db\models
> \fields\files.py", line 58, in _get_url
>     self._require_file()
>   File "C:\Python25\Lib\site-packages\django-trunk\django\db\models
> \fields\files.py", line 43, in _require_file
>     raise ValueError("The '%s' attribute has no file associated with
> it." % self.field.name)
> ValueError: The 'image' attribute has no file associated with it.
>
> C:\Python25\Lib\site-packages\django-trunk\django\template\debug.py in
> render_node
>
>   74. e.source = node.source
>   75. raise
>   76. except Exception, e:
>   77. from sys import exc_info
>   78. wrapped = TemplateSyntaxError(u'Caught an exception while
> rendering: %s' % force_unicode(e, errors='replace'))
>   79. wrapped.source = node.source
>   80. wrapped.exc_info = exc_info()
>
>   81. raise wrapped  # error highlighted on this line
>
>   82. return result
>   83.
>   84. class DebugVariableNode(VariableNode):
>   85. def render(self, context):
>   86. try:
>   87. output = force_unicode(self.filter_expression.resolve(context))
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: ImageField, width_field, height_field not working

2009-02-04 Thread alex.gay...@gmail.com



On Feb 4, 3:48 pm, vicvicvic  wrote:
> Hello!
>
> I have created a ticket for this issue, with a patch which solves it.
> I don't think it breaks anything...
>
> http://code.djangoproject.com/ticket/10196

That patch does indeed look to be correct, if you haven't already run
the test suite to ensure nothing breaks, and try to add an additional
test case to show that this solves the problem.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: ImageField, width_field, height_field not working

2009-02-04 Thread vicvicvic

Hello!

I have created a ticket for this issue, with a patch which solves it.
I don't think it breaks anything...

http://code.djangoproject.com/ticket/10196

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



Re: ImageField, width_field, height_field not working

2009-02-03 Thread A Melé

It seems that after rev. 9766 ImageFieldFile's save() method (where it
sets values for height_field and width_field) is bypassed when saving
the file (at least with the admin). I use FieldFiles that inherit from
ImageFieldFile (for example in django-thumbs code (thanks for
reporting the issue, Andrew)) and I override the ImageFieldFile's save
() method with custom code. That code doesn't get executed when saving
the file with the admin when using rev.9766 and later revisions.

Regards,
Antonio Melé
http://django.es/

On 24 ene, 03:21, Andrew Ingram  wrote:
> Malcolm Tredinnick wrote:
> > So the next thing is to narrow down which commit. You know a good commit
> > and you know a bad one. Now pick something halfway in between and try
> > that. Continue with binary searching. It won't take many repetitions to
> > get to the precise commit.
>
> > Regards,
> > Malcolm
>
> I've narrowed it down to revision 9766:
>
> "Fixed #10044: You can now assign directly to file fields
> (`instance.filefield = somefile`)."
>
> http://code.djangoproject.com/ticket/10044
>
> It's late now, but I'll update the ticket tommorrow if nobody else has
> by then.
>
> Regards,
> Andrew Ingram
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: ImageField, width_field, height_field not working

2009-01-23 Thread Andrew Ingram


Malcolm Tredinnick wrote:
> So the next thing is to narrow down which commit. You know a good commit
> and you know a bad one. Now pick something halfway in between and try
> that. Continue with binary searching. It won't take many repetitions to
> get to the precise commit.
>
> Regards,
> Malcolm
>   
I've narrowed it down to revision 9766:

"Fixed #10044: You can now assign directly to file fields 
(`instance.filefield = somefile`)."

http://code.djangoproject.com/ticket/10044

It's late now, but I'll update the ticket tommorrow if nobody else has 
by then.

Regards,
Andrew Ingram

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



Re: ImageField image upload problems

2009-01-23 Thread Malcolm Tredinnick

On Fri, 2009-01-23 at 15:47 -0800, Foxpl wrote:
> Hi, i have errors while i am trying to upload image by an admin panel.
> 
> Here is my image model:
> 
> class Photo(models.Model):
> Title = models.CharField(max_length=256)
> Description = models.TextField(max_length=1024, blank=True)
> User = models.ForeignKey(User)
> File = models.ImageField(upload_to='photos/%Y/%m/%d',
> height_field=60, width_field=468)

Reread the documentation for height_field and width_field. They aren't
numbers. They are the names of other attributes on the model (and,
hence, have to be strings. In fact, valid Python identifiers).

Regards,
Malcolm



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



Re: ImageField, width_field, height_field not working

2009-01-23 Thread Malcolm Tredinnick

On Fri, 2009-01-23 at 15:19 -0800, Andrew Ingram wrote:
> I reverted Django to revision 9756 (just after aggregation was merged
> in) and everyone works fine, so evidently a commit made in the last
> few days has caused this issue.

So the next thing is to narrow down which commit. You know a good commit
and you know a bad one. Now pick something halfway in between and try
that. Continue with binary searching. It won't take many repetitions to
get to the precise commit.

Regards,
Malcolm



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



Re: ImageField, width_field, height_field not working

2009-01-23 Thread Andrew Ingram

I reverted Django to revision 9756 (just after aggregation was merged
in) and everyone works fine, so evidently a commit made in the last
few days has caused this issue.

Regards,
Andrew Ingram

On Jan 23, 6:40 pm, Andrew Ingram  wrote:
> I've just tried saving the model using the approach followed in Django's
> unit test and the database gets populated correctly, this reinforces the
> likelihood of it being an admin-related issue.
>
> Regards,
> Andrew Ingram,
>
> Karen Tracey wrote:
> >http://code.djangoproject.com/ticket/9545
>
> > also reports these fields not working, which I found a little
> > mysterious since the function is tested in the test suite.  Your
> > report provides a clue that the problem may be specifically with the
> > admin (though the ticket doesn't mention admin), where (without
> > actually looking at any code) I could guess the path taken to save the
> > new model with an uploaded image somehow bypasses however these fields
> > are normally set.  You might want to note in that ticket how you are
> > encountering this problem in the admin.  The ticket also notes a
> > custom save method can be used to get around the problem, which you
> > may want to try if you want to get things working before the root
> > cause of the problem is identified and fixed.
>
> > Karen
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: ImageField, width_field, height_field not working

2009-01-23 Thread Andrew Ingram

I've just tried saving the model using the approach followed in Django's 
unit test and the database gets populated correctly, this reinforces the 
likelihood of it being an admin-related issue.

Regards,
Andrew Ingram,


Karen Tracey wrote:
> http://code.djangoproject.com/ticket/9545
>
> also reports these fields not working, which I found a little 
> mysterious since the function is tested in the test suite.  Your 
> report provides a clue that the problem may be specifically with the 
> admin (though the ticket doesn't mention admin), where (without 
> actually looking at any code) I could guess the path taken to save the 
> new model with an uploaded image somehow bypasses however these fields 
> are normally set.  You might want to note in that ticket how you are 
> encountering this problem in the admin.  The ticket also notes a 
> custom save method can be used to get around the problem, which you 
> may want to try if you want to get things working before the root 
> cause of the problem is identified and fixed.
>
> Karen
>
> >


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



Re: ImageField, width_field, height_field not working

2009-01-23 Thread Andrew Ingram

Thanks for your response Karen,

I've tried the workaround in the ticket and I get this error:

Exception Type:  AttributeError
Exception Value: 'InMemoryUploadedFile' object has no attribute 
'width'

I have a vague recollection that this was actually working before I did 
the latest update on Django


Karen Tracey wrote:
> http://code.djangoproject.com/ticket/9545
>
> also reports these fields not working, which I found a little 
> mysterious since the function is tested in the test suite.  Your 
> report provides a clue that the problem may be specifically with the 
> admin (though the ticket doesn't mention admin), where (without 
> actually looking at any code) I could guess the path taken to save the 
> new model with an uploaded image somehow bypasses however these fields 
> are normally set.  You might want to note in that ticket how you are 
> encountering this problem in the admin.  The ticket also notes a 
> custom save method can be used to get around the problem, which you 
> may want to try if you want to get things working before the root 
> cause of the problem is identified and fixed.
>
> Karen
>
> >


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



Re: ImageField, width_field, height_field not working

2009-01-23 Thread Karen Tracey
On Fri, Jan 23, 2009 at 6:55 AM, Andrew Ingram wrote:

>
> Hi
>
> I am trying to use the height_field and width_field arguments for
> ImageField to auto-populate the dimension of images to other fields, but
> it doesn't seem to be working.
>
> I've duplicated the usage that's in Django's test suite (which
> incidentally is the only mention I can find that you have to pass the
> fields as strings rather than passing the fields themselves), and I've
> produced the following model for testing this (after it didn't work on
> my regular model).
>
> class Test(models.Model):
>image =
>
> models.ImageField(upload_to='banners',height_field='image_height',width_field='image_width')
>
>image_width = models.PositiveSmallIntegerField(editable=False)
>image_height = models.PositiveSmallIntegerField(editable=False)
>
> But when I try to upload the Image I get the following exception:
>
> Exception Type: IntegrityError at /admin/banners/test/add/
> Exception Value: (1048, "Column 'image_width' cannot be null")
>
> If I allow the image_width and image_height fields to be Null, the image
> itself gets uploaded fine but the dimension fields don't get populated.
>
> I'm on Mac OSX 10.5 and I'm using the very latest revision of trunk. PIL
> is installed and working.
>

http://code.djangoproject.com/ticket/9545

also reports these fields not working, which I found a little mysterious
since the function is tested in the test suite.  Your report provides a clue
that the problem may be specifically with the admin (though the ticket
doesn't mention admin), where (without actually looking at any code) I could
guess the path taken to save the new model with an uploaded image somehow
bypasses however these fields are normally set.  You might want to note in
that ticket how you are encountering this problem in the admin.  The ticket
also notes a custom save method can be used to get around the problem, which
you may want to try if you want to get things working before the root cause
of the problem is identified and fixed.

Karen

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



Re: ImageField upload_to not workin

2008-11-17 Thread elm

Hi Javier,

I am experiencing the same problem with 'upload_to'.  Have you found
the problem?

Thx,

elm

On 14 nov, 18:31, Javier <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I've create a model:
>
> class ImagenesLugar(models.Model):
>     archivo = models.ImageField(upload_to="imageneslugar/")
>     texto = models.CharField(max_length=400)
>
> The thing is that when i create a new instance of this model and
> assign instance.archivo to a file then instance.archivo.path does not
> contain myupload_toparameter:
>
> Ie:
>
> my media root is :"/home/media"
> my uploadto is "imageneslugar"
> my file is "image.jpg"
>
> I do:
> instance.archivo = "image.jpg"
>
> then:
> instance.archivo.path is:
> /home/media/image.jpg
> instead of
> /home/media/imageneslugar/image.jpg
>
> what am I missing?

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: imagefield write error

2008-11-17 Thread prem1er

Ok, I figured that one out.  I should be writing to within my Django
project.  How would I get this to work with apache permission?

On Nov 17, 8:51 pm, prem1er <[EMAIL PROTECTED]> wrote:
> Trying to write an image to my server for a user.  I keep getting the
> error 'SuspiciousOperation, Attempted access to '.../' denied.  I
> tried adding read write and execute permissions to this directory and
> still no luck.
>
> from django.db import models
>
> class user(models.Model):
>         avatar = models.ImageField(upload_to='/tmp')
>
>         def __unicode__(self):
>                 return self.userName
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField upload_to not workin

2008-11-14 Thread Peter Bengtsson



On Nov 14, 9:31 pm, Javier <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I've create a model:
>
> class ImagenesLugar(models.Model):
>     archivo = models.ImageField(upload_to="imageneslugar/")
>     texto = models.CharField(max_length=400)
>
> The thing is that when i create a new instance of this model and
> assign instance.archivo to a file then instance.archivo.path does not
> contain my upload_to parameter:
>
> Ie:
>
> my media root is :"/home/media"
> my uploadto is "imageneslugar"
> my file is "image.jpg"
>
> I do:
> instance.archivo = "image.jpg"

Is this pseudo code or does that actually work? I do this:
instance.achivo.save('image.jpg', request.FILES['photo'])

>
> then:
> instance.archivo.path is:
> /home/media/image.jpg
> instead of
> /home/media/imageneslugar/image.jpg
>
> what am I missing?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField: upload_to

2008-09-18 Thread lingrlongr

worked like a charm.  thx.

On Sep 18, 5:21 pm, gnijholt <[EMAIL PROTECTED]> wrote:
> I had to define the callable function before it gets called.
> So in your case I'd put it right under class Product(models.model)
> Then you should be able to just do:
>   upload_to=get_image_path
>
> Cheers,
>
> On Sep 18, 10:20 pm, lingrlongr <[EMAIL PROTECTED]> wrote:
>
> > According to the documentation, I can make the upload_to argument a
> > callable (which must receive 2 args):
>
> > class Product(models.Model):
> >     number = models.CharField(max_length=20)
> >     image = models.ImageField(upload_to='')
>
> > I want to build a path so it looks like this (with respect to
> > MEDIA_URL):
> >   images/products//
>
> > def get_image_path(instance, filename):
> >   return 'images/products/%s/%s' % (instance.number, filename)
>
> > I tried:
> >   upload_to='get_image_path'
> >   upload_to=get_image_path
> >   upload_to=get_image_path()
> >   upload_to=self.get_image_path
>
> > How can I accomplish that?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField: upload_to

2008-09-18 Thread gnijholt

I had to define the callable function before it gets called.
So in your case I'd put it right under class Product(models.model)
Then you should be able to just do:
  upload_to=get_image_path

Cheers,

On Sep 18, 10:20 pm, lingrlongr <[EMAIL PROTECTED]> wrote:
> According to the documentation, I can make the upload_to argument a
> callable (which must receive 2 args):
>
> class Product(models.Model):
>     number = models.CharField(max_length=20)
>     image = models.ImageField(upload_to='')
>
> I want to build a path so it looks like this (with respect to
> MEDIA_URL):
>   images/products//
>
> def get_image_path(instance, filename):
>   return 'images/products/%s/%s' % (instance.number, filename)
>
> I tried:
>   upload_to='get_image_path'
>   upload_to=get_image_path
>   upload_to=get_image_path()
>   upload_to=self.get_image_path
>
> How can I accomplish that?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField

2008-09-11 Thread lingrlongr

Ah, I figured it out.

class ProductImage(models.Model):
  image = models.ImageField(upload_to='images', height_field='height',
width_field='width')

Example:
>>> p = ProductImage.objects.all()[0]
>>> p.image.height
250
>>> p.image.width
100



On Sep 12, 12:06 am, lingrlongr <[EMAIL PROTECTED]> wrote:
> Can someone explain how to use theheight_fieldand width_field for an
> ImageField as it would relate to this model:
>
> class ProductImage(models.Model):
>   image = models.ImageField(upload_to='images')
>
> The explanation in the documentation is:
> Name of a model field which will be auto-populated with the height of
> the image each time the model instance is saved.
>
> I don't think that's 100% clear.  At least to me its not.  I tried
> this:
>
> class ProductImage(models.Model):
>   height = models.IntegerField()
>   width = models.IntegerField()
>   image = models.ImageField(upload_to='images',height_field=height,
> width_field=width)
>
> Must I do anything else specific with my model or am I way off?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField validation

2008-08-22 Thread Michael Sanders

On Aug 22, 3:38 pm, "Marty Alchin" <[EMAIL PROTECTED]> wrote:
> You should really be using forms here, even though you're not
> submitting them through the normal channels. This would allow you to
> use form-level validations, which are designed precisely for these
> types of situations. Just create a form (probably a ModelForm) that
> matches whatever you intend to post back to the server, and pass
> request.POST and request.FILES into that and use its .is_valid()
> method to force the proper validations to run.

OK, I'll try creating a form.

Many thanks,
Michael
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField validation

2008-08-22 Thread Marty Alchin

On Fri, Aug 22, 2008 at 10:22 AM, Michael Sanders <[EMAIL PROTECTED]> wrote:
> Is this a consequence of http://code.djangoproject.com/changeset/8348
> or should I be doing something else to enable this validation? (I have
> PIL installed). Would it be preferable to use a Django form for the
> image upload & would it make any difference?

You could test that fairly easily by rolling back to a revision prior
to r8348 to see if it works properly there, but I doubt it would.
Model-level validation didn't really work before that revision either,
so your example view was never triggering anything to even check
whether it's an image or not.

You should really be using forms here, even though you're not
submitting them through the normal channels. This would allow you to
use form-level validations, which are designed precisely for these
types of situations. Just create a form (probably a ModelForm) that
matches whatever you intend to post back to the server, and pass
request.POST and request.FILES into that and use its .is_valid()
method to force the proper validations to run.

-Gul

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField save issues (IOError: [Errno 37] No locks available)

2008-08-18 Thread Malcolm Tredinnick


On Mon, 2008-08-18 at 17:23 -0700, wnielson wrote:
> For what its worth, I did manage a work around on the NFS side.  In /
> etc/export you need to have the `no_subtree_check` option enabled.
> Apparently this has mild security implications (as stated in man
> exports), but it does allow the locking to work properly.

I've opened #8043 anyway, since not everybody is going to have the
ability to reconfigure the NFS mount options. A big, hulking sysadmin
may be standing between them and the config file, for example. Which
makes this a bit of a showstopper in that case. Fortunately, it looks
like it's ultimately solvable.

Regards,
Malcolm



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField save issues (IOError: [Errno 37] No locks available)

2008-08-18 Thread wnielson

For what its worth, I did manage a work around on the NFS side.  In /
etc/export you need to have the `no_subtree_check` option enabled.
Apparently this has mild security implications (as stated in man
exports), but it does allow the locking to work properly.

Thanks for the insight Malcolm.

Cheers,
Wes

On Aug 19, 12:48 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Mon, 2008-08-18 at 16:42 -0700, wnielson wrote:
> > Thanks for the quick response.  Yes, I did do some searching and ran
> > across the post about NFS (and yes I am using an NFS mount).  However,
> > I can solve the problem by bypassing the `save` method like so:
>
> > from django.core.files import File
>
> > f = open('my_filename.jpg', 'w')
> > myfile = File(f)
> > myfile.write(image.read())
> > sm.image = myfile
>
> > I suppose this method works because it bypasses the `save` method's
> > use of the lock.
>
> Precisely. Which makes it subject to race conditions and lots of
> problems because of that.
>
> You could also avoid the problem by not saving your file at all. Both
> options are just symptom patching, rather than a solution to the
> problem. :-)
>
> Looks like we need to switch from flock-based locking to fcntl-based
> locking where available. *sigh*. I'll take care of opening a ticket for
> this.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField save issues (IOError: [Errno 37] No locks available)

2008-08-18 Thread Malcolm Tredinnick


On Mon, 2008-08-18 at 16:42 -0700, wnielson wrote:
> Thanks for the quick response.  Yes, I did do some searching and ran
> across the post about NFS (and yes I am using an NFS mount).  However,
> I can solve the problem by bypassing the `save` method like so:
> 
> from django.core.files import File
> 
> f = open('my_filename.jpg', 'w')
> myfile = File(f)
> myfile.write(image.read())
> sm.image = myfile
> 
> I suppose this method works because it bypasses the `save` method's
> use of the lock.

Precisely. Which makes it subject to race conditions and lots of
problems because of that.

You could also avoid the problem by not saving your file at all. Both
options are just symptom patching, rather than a solution to the
problem. :-)

Looks like we need to switch from flock-based locking to fcntl-based
locking where available. *sigh*. I'll take care of opening a ticket for
this.

Regards,
Malcolm


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField save issues (IOError: [Errno 37] No locks available)

2008-08-18 Thread wnielson

Thanks for the quick response.  Yes, I did do some searching and ran
across the post about NFS (and yes I am using an NFS mount).  However,
I can solve the problem by bypassing the `save` method like so:

from django.core.files import File

f = open('my_filename.jpg', 'w')
myfile = File(f)
myfile.write(image.read())
sm.image = myfile

I suppose this method works because it bypasses the `save` method's
use of the lock.

On Aug 19, 12:16 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Mon, 2008-08-18 at 16:05 -0700, wnielson wrote:
> > I've been running into an issue while trying to upgrade my code to use
> > Django's new file handling system.  When I try to use the `save`
> > method of a `ImageField` instance, I get an `IOError: [Errno 37] No
> > locks available`.  The file gets created but nothing is ever written
> > to it.  Here is a basic example that illustrates the issue I keep
> > running into.
>
> We need some more details about your particular setup. Are you trying to
> save to an NFS mounted filesystem? A bit of searching on Google for that
> error message (which hopefully you also did before posting to the
> mailing list, right?) shows that it's possible there.
>
> If you're not using an NFS_mounted system as the destination, what sort
> of OS and filesystem are you trying to save to? Do things change if you
> target the file saves to somewhere else that is more or less guaranteed
> to be locally mounted (e.g. /tmp on a Unix system)?
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField save issues (IOError: [Errno 37] No locks available)

2008-08-18 Thread Malcolm Tredinnick


On Mon, 2008-08-18 at 16:05 -0700, wnielson wrote:
> I've been running into an issue while trying to upgrade my code to use
> Django's new file handling system.  When I try to use the `save`
> method of a `ImageField` instance, I get an `IOError: [Errno 37] No
> locks available`.  The file gets created but nothing is ever written
> to it.  Here is a basic example that illustrates the issue I keep
> running into.

We need some more details about your particular setup. Are you trying to
save to an NFS mounted filesystem? A bit of searching on Google for that
error message (which hopefully you also did before posting to the
mailing list, right?) shows that it's possible there.

If you're not using an NFS_mounted system as the destination, what sort
of OS and filesystem are you trying to save to? Do things change if you
target the file saves to somewhere else that is more or less guaranteed
to be locally mounted (e.g. /tmp on a Unix system)?

Regards,
Malcolm



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField error

2008-07-07 Thread Molly

Milan,

Thanks a lot, that fixed my problem :)

Molly


On Jul 7, 12:49 am, "Milan Andric" <[EMAIL PROTECTED]> wrote:
> On Sun, Jul 6, 2008 at 3:12 PM, Molly <[EMAIL PROTECTED]> wrote:
>
> > Millan,
>
> > I'm doing this in dev environment with the built in webserver. No it's
> > not a mod_python error.
>
> > I'm using the static setup and I can get to it fine when I upload my
> > photo.
> > The problem is when I click the photo it seems to be pointing to
> > somewhere else.
>
> > In my models:
> > ==
> > photo = models.ImageField("Photograph", upload_to='images/uploaded',
> > blank=True,null=True)
> > ==
>
> > if i manually go to /images/uploaded my photo is there, but the link
> > in the admin site seems to be wrong.
>
> > this is the link, it's adding all of the extra information:
> > ==
> >http://127.0.0.1:8000/admin/base/incident/1/media/images/uploaded/DCP...
> > ==
>
> What do you have for MEDIA_URL in your settings.py file?  Should be
> something like MEDIA_URL='/media/', my guess is you are missing a
> leading slash.  If you can paste your settings.py and model that would
> help,http://dpaste.com.
>
> --
> Milan
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField error

2008-07-06 Thread Milan Andric

On Sun, Jul 6, 2008 at 3:12 PM, Molly <[EMAIL PROTECTED]> wrote:
>
> Millan,
>
> I'm doing this in dev environment with the built in webserver. No it's
> not a mod_python error.
>
> I'm using the static setup and I can get to it fine when I upload my
> photo.
> The problem is when I click the photo it seems to be pointing to
> somewhere else.
>
> In my models:
> ==
> photo = models.ImageField("Photograph", upload_to='images/uploaded',
> blank=True,null=True)
> ==
>
> if i manually go to /images/uploaded my photo is there, but the link
> in the admin site seems to be wrong.
>
> this is the link, it's adding all of the extra information:
> ==
> http://127.0.0.1:8000/admin/base/incident/1/media/images/uploaded/DCP_0326.JPG
> ==

What do you have for MEDIA_URL in your settings.py file?  Should be
something like MEDIA_URL='/media/', my guess is you are missing a
leading slash.  If you can paste your settings.py and model that would
help, http://dpaste.com .

--
Milan

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField error

2008-07-06 Thread Molly

Millan,

I'm doing this in dev environment with the built in webserver. No it's
not a mod_python error.

I'm using the static setup and I can get to it fine when I upload my
photo.
The problem is when I click the photo it seems to be pointing to
somewhere else.

In my models:
==
photo = models.ImageField("Photograph", upload_to='images/uploaded',
blank=True,null=True)
==

if i manually go to /images/uploaded my photo is there, but the link
in the admin site seems to be wrong.

this is the link, it's adding all of the extra information:
==
http://127.0.0.1:8000/admin/base/incident/1/media/images/uploaded/DCP_0326.JPG
==

Thanks a lot for your response. Sorry it took me awhile to respond, I
was out of town for the past few days.

Molly
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField error

2008-07-02 Thread Milan Andric

On Wed, Jul 2, 2008 at 12:21 PM, Molly <[EMAIL PROTECTED]> wrote:
>
> I added ImageField to my models like this:
>
> 
> photo = models.ImageField("Photograph", upload_to='media/images',
> blank=True,null=True)
> 
>
> I "import Image" in my imports, and in my models I:
>
> 
> from django.db.models import ImageField
> 
>
> Everything works.. it shows up on my site, I upload it and it is
> there. When I open the picture, i get this error:
>
> 
> error: (10061, 'Connection refused')
> 
>
> I would appreciate any help!
>
> Thank you!!

Molly,

Are you doing this in your dev. environment with the built in
webserver or on a production setup?  Just wondering about the
connection error, never heard of it.  Is that a mod_python error?
Maybe you can post the entire stack trace if you have it at
http://dpaste.com/ ?

If you are serving static media, you should be able to copy an image
in your media dir and manually type in the URL to get it.

Also  have a look here, many people use this type of setup in their
dev environment to serve static media using django.views.static.serve.

http://www.djangoproject.com/documentation/static_files/#limiting-use-to-debug-true

--
Milan

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField

2008-06-25 Thread Molly

Solved. I had to import Image without the PIL

On Jun 25, 9:24 am, Molly <[EMAIL PROTECTED]> wrote:
> Nevermind, I figured out how to import it.. it works now when I say
> import Image.
>
> When I go to run my app it does not work with that import.
> The import I added is:
>
> import PIL.image
>
> Thanks :)
> Molly
>
> On Jun 25, 9:19 am, Molly <[EMAIL PROTECTED]> wrote:
>
> > This is what I got:
>
> > C:\>python
> > Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
> > (Intel)] on
> > win32
> > Type "help", "copyright", "credits" or "license" for more information.>>> 
> > import Image
>
> > Traceback (most recent call last):
> >   File "", line 1, in 
> > ImportError: No module named Image
>
> > Do I need to add it to my imports?? if so, how would I do that?
>
> > Thanks!
> > Molly
>
> > On Jun 25, 4:26 am, David Reynolds <[EMAIL PROTECTED]>
> > wrote:
>
> > > On 24 Jun 2008, at 6:36 pm, Molly wrote:
>
> > > > Maybe my Python Imaging Library is in the wrong location??
>
> > > Try this:
>
> > > $ python
> > > Python 2.5.2 (r252:60911, May 28 2008, 08:35:32)
> > > [GCC 4.2.4 (Debian 4.2.4-1)] on linux2
> > > Type "help", "copyright", "credits" or "license" for more information.
> > > (InteractiveConsole)
> > >  >>> import Image
>
> > > --
> > > David Reynolds
> > > [EMAIL PROTECTED]
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField

2008-06-25 Thread Molly

Nevermind, I figured out how to import it.. it works now when I say
import Image.

When I go to run my app it does not work with that import.
The import I added is:

import PIL.image

Thanks :)
Molly

On Jun 25, 9:19 am, Molly <[EMAIL PROTECTED]> wrote:
> This is what I got:
>
> C:\>python
> Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
> (Intel)] on
> win32
> Type "help", "copyright", "credits" or "license" for more information.>>> 
> import Image
>
> Traceback (most recent call last):
>   File "", line 1, in 
> ImportError: No module named Image
>
>
>
> Do I need to add it to my imports?? if so, how would I do that?
>
> Thanks!
> Molly
>
> On Jun 25, 4:26 am, David Reynolds <[EMAIL PROTECTED]>
> wrote:
>
> > On 24 Jun 2008, at 6:36 pm, Molly wrote:
>
> > > Maybe my Python Imaging Library is in the wrong location??
>
> > Try this:
>
> > $ python
> > Python 2.5.2 (r252:60911, May 28 2008, 08:35:32)
> > [GCC 4.2.4 (Debian 4.2.4-1)] on linux2
> > Type "help", "copyright", "credits" or "license" for more information.
> > (InteractiveConsole)
> >  >>> import Image
>
> > --
> > David Reynolds
> > [EMAIL PROTECTED]
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField

2008-06-25 Thread Molly

This is what I got:

C:\>python
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import Image
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named Image
>>>

Do I need to add it to my imports?? if so, how would I do that?

Thanks!
Molly

On Jun 25, 4:26 am, David Reynolds <[EMAIL PROTECTED]>
wrote:
> On 24 Jun 2008, at 6:36 pm, Molly wrote:
>
> > Maybe my Python Imaging Library is in the wrong location??
>
> Try this:
>
> $ python
> Python 2.5.2 (r252:60911, May 28 2008, 08:35:32)
> [GCC 4.2.4 (Debian 4.2.4-1)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> (InteractiveConsole)
>  >>> import Image
>
> --
> David Reynolds
> [EMAIL PROTECTED]
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField

2008-06-25 Thread David Reynolds


On 24 Jun 2008, at 6:36 pm, Molly wrote:

> Maybe my Python Imaging Library is in the wrong location??


Try this:

$ python
Python 2.5.2 (r252:60911, May 28 2008, 08:35:32)
[GCC 4.2.4 (Debian 4.2.4-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
 >>> import Image


-- 
David Reynolds
[EMAIL PROTECTED]


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField

2008-06-24 Thread Molly

I just looked it over and it seems as though this is all I need to do:

===
class PhotoDocumentation(models.Model):
image = models.ImageField(upload_to='/media/images')
caption = models.CharField(max_length=100)

def __unicode__(self):
return self.name

class Admin:
pass
===

I have installed the Photo Imaging Library, and when I sync my db this
is the error I get:

===
C:\dev\incidents>C:\Python25\python C:\dev\incidents\manage.py syncdb
Error: One or more models did not validate:
base.photodocumentation: "image": To use ImageFields, you need to
install the Py
thon Imaging Library. Get it at http://www.pythonware.com/products/pil/
.
===

Maybe my Python Imaging Library is in the wrong location??

Thanks :)
Molly
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField

2008-06-24 Thread joshuajonah

Have you read the djangobook.com documentation? It's a great cross
reference to the django documentation, written by the same person
aswell, for some reason.

On Jun 24, 1:10 pm, Molly <[EMAIL PROTECTED]> wrote:
> I was wondering if anyone could explain ImageField to me or know of a
> good website to explain it.. I have been trying and can't get it to
> work. I have read through the documentation but no luck.
>
> Thanks :)
> Molly
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField get_X_url() method not respecting MEDIA_URL?

2008-06-04 Thread chris . czub

Thanks, that was it.

-Chris

On Jun 3, 5:44 pm, "Marty Alchin" <[EMAIL PROTECTED]> wrote:
> On Tue, Jun 3, 2008 at 5:15 PM, Chris Czub <[EMAIL PROTECTED]> wrote:
> > # URL that handles the media served from MEDIA_ROOT.
> > # Example: "http://media.lawrence.com;
> > MEDIA_URL = 'http://www.mysite.com/media'
>
> > which is correct - the url of the image SHOULD be
>
> >http://www.mysite.com/media/uploads/20080603151319/rrbk.jpg
>
> Unfortunately, that's not correct. Your MEDIA_URL setting needs a
> trailing slash in order for Python's urljoin() method to realize that
> it's a directory that needs to stay, not just a file that should be
> replaced. Change it to 'http://www.mysite.com/media/'and you should
> be fine.
>
> More recent (from just over a year ago) checkouts of Django have an
> additional comment added into the default settings.py to outline this
> more clearly.
>
> # URL that handles the media served from MEDIA_ROOT. Make sure to use a
> # trailing slash if there is a path component (optional in other cases).
> # Examples: "http://media.lawrence.com;, "http://example.com/media/;
>
> -Gul
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField get_X_url() method not respecting MEDIA_URL?

2008-06-03 Thread Marty Alchin

On Tue, Jun 3, 2008 at 5:15 PM, Chris Czub <[EMAIL PROTECTED]> wrote:
> # URL that handles the media served from MEDIA_ROOT.
> # Example: "http://media.lawrence.com;
> MEDIA_URL = 'http://www.mysite.com/media'
>
>
> which is correct - the url of the image SHOULD be
>
> http://www.mysite.com/media/uploads/20080603151319/rrbk.jpg

Unfortunately, that's not correct. Your MEDIA_URL setting needs a
trailing slash in order for Python's urljoin() method to realize that
it's a directory that needs to stay, not just a file that should be
replaced. Change it to 'http://www.mysite.com/media/' and you should
be fine.

More recent (from just over a year ago) checkouts of Django have an
additional comment added into the default settings.py to outline this
more clearly.

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com;, "http://example.com/media/;

-Gul

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField links in admin going no-where

2008-04-06 Thread bergstyle

I got this working. My media url wasn't setup right. If anyone else
encounters this issue. I setup my media_url in the settings file and
then I point /media to that directory in the web server config. Then
for the admin files I created a symlink to them from inside my regular
media directory.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField Example

2008-01-20 Thread Alex Koshelev

Read the docs
http://www.djangoproject.com/documentation/newforms/#binding-uploaded-files-to-a-form

On 19 янв, 15:32, Darthmahon <[EMAIL PROTECTED]> wrote:
> Hey,
>
> Does anyone have a working example of uploading images using Django?
> I've looked extensively and haven't found anything - any idea how I
> save images using Django? I've put an ImageField in my model with the
> path to where it should save, but how do I tell Django to save it when
> a form is submitted? I'm using NewForms btw.
>
> Cheers,
> Chris
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField Example

2008-01-19 Thread Kenneth Gonsalves


On 19-Jan-08, at 6:02 PM, Darthmahon wrote:

> Does anyone have a working example of uploading images using Django?
> I've looked extensively and haven't found anything - any idea how I
> save images using Django? I've put an ImageField in my model with the
> path to where it should save, but how do I tell Django to save it when
> a form is submitted? I'm using NewForms btw.

http://www.djangosnippets.org/snippets/463/

-- 

regards
kg
http://lawgon.livejournal.com
http://nrcfosshelpline.in/web/
Foss Conference for the common man: http://registration.fossconf.in/web/



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField: separating text field from button

2008-01-01 Thread Karen Tracey
On Jan 1, 2008 10:30 AM, Przemek Gawronski <[EMAIL PROTECTED]>
wrote:

>
> > can you explain a bit clearly what you want to do?
>
> If I have a form (newform) with a ImageFiled (probably the same with a
> FileField) and in the template I use {{ form }} to display this form,
> the text field and the button you press to select a file are right next
> to each other, and I want some space between them.
>

I don't know if this can be done.  It's not a limitation of Django but
rather of the input type=file HTML control.  Django lets you specify attrs
for the FileInput widget, but I haven't found any that provide spacing
between the text input box and the browse button.  You can change the size
of the text box by specifying a "size" attr.  However, CSS style attributes
seem to apply to the two things together, thus for example a margin-right
specification puts a margin to the right of the browse button, not to the
right of the text input box.  I've found a few pages that talk about the
difficulty of styling this control.  This one in particular I thought was
good:

http://www.cs.tut.fi/~jkorpela/forms/file.html#present

It's got a lot of pointers to other references so perhaps if you follow them
further than I did you could find something that will help, though I tend to
doubt it.  This control sounds notoriously difficult to customize.

Karen

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField: separating text field from button

2008-01-01 Thread Przemek Gawronski

> can you explain a bit clearly what you want to do?

If I have a form (newform) with a ImageFiled (probably the same with a
FileField) and in the template I use {{ form }} to display this form,
the text field and the button you press to select a file are right next
to each other, and I want some space between them.

Przemek
-- 
AIKIDO TANREN DOJO  -   Poland - Warsaw - Mokotow - Ursynow - Natolin
info:  http://tanren.pl/   phone:+4850151   mailto:[EMAIL PROTECTED]

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField: separating text field from button

2008-01-01 Thread Kenneth Gonsalves


On 01-Jan-08, at 6:36 PM, Przemek Gawronski wrote:

> Hi, I want to separate the file name text field from 'select'  
> button in
> ImageField from newforms. What would be the cleanest way to do this?

can you explain a bit clearly what you want to do?

-- 

regards
kg
http://lawgon.livejournal.com
http://nrcfosshelpline.in/web/
Foss Conference for the common man: http://registration.fossconf.in/web/



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField and save method

2007-12-10 Thread Julien

Hey, thanks guys, now I understand a little better.

One of the articles you're pointing says:
"Currently, the only technique you can reliably use is to override
_save_FIELD_file on your model. This isn't quite the same as
save_FOO_file that's officially documented."

I in fact followed the documentation and that led me in the wrong
direction...

Anyway, now it's working so that's cool!

On Dec 11, 12:44 am, "Marty Alchin" <[EMAIL PROTECTED]> wrote:
> On Dec 10, 2007 7:46 AM, Julien <[EMAIL PROTECTED]> wrote:
>
> > In the following example, the "save_avatar_file" method is never
> > called. However the "_save_FIELD_file" method is called.
> > It looks a bit dirty to me, and I'd like to get rid of the
> > "_save_FIELD_file method", to only use a method for a given field (in
> > this case, "save_avatar_file").
>
> > Do you know why it's not working as expected?
>
> Believe it or not, this is working as expected. At least, to those of
> us who know what to expect. When your model is read in by Python,
> Django automatically creates a new save_avatar_file() and attaches it
> to your model, which will override any such method you define. It's
> not pretty, but it's how it works.
>
> As with many FileField-related issues, this behavior will be changing
> once I get my rewrite finished, which should be fairly soon. I'm still
> working out a few backward-compatibility issues, but it's nearly
> ready. Once it gets committed to trunk, I'll do a full writeup on how
> to accomplish things like what you're trying to do.
>
> Until then, take a look at Scott Barnham's article[1] about renaming
> files in a way that should work for you.
>
> -Gul
>
> [1]http://scottbarnham.com/blog/2007/07/31/uploading-images-to-a-dynamic...
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField and save method

2007-12-10 Thread Marty Alchin

On Dec 10, 2007 7:46 AM, Julien <[EMAIL PROTECTED]> wrote:
> In the following example, the "save_avatar_file" method is never
> called. However the "_save_FIELD_file" method is called.
> It looks a bit dirty to me, and I'd like to get rid of the
> "_save_FIELD_file method", to only use a method for a given field (in
> this case, "save_avatar_file").
>
> Do you know why it's not working as expected?

Believe it or not, this is working as expected. At least, to those of
us who know what to expect. When your model is read in by Python,
Django automatically creates a new save_avatar_file() and attaches it
to your model, which will override any such method you define. It's
not pretty, but it's how it works.

As with many FileField-related issues, this behavior will be changing
once I get my rewrite finished, which should be fairly soon. I'm still
working out a few backward-compatibility issues, but it's nearly
ready. Once it gets committed to trunk, I'll do a full writeup on how
to accomplish things like what you're trying to do.

Until then, take a look at Scott Barnham's article[1] about renaming
files in a way that should work for you.

-Gul

[1] 
http://scottbarnham.com/blog/2007/07/31/uploading-images-to-a-dynamic-path-with-django/

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField and save method

2007-12-10 Thread Thomas

I think this provides more (partially) detail:
http://gulopine.gamemusic.org/2007/11/customizing-filenames-without-patching.html

Thomas

On Dec 10, 2:01 pm, Julien <[EMAIL PROTECTED]> wrote:
> I don't explicitly call it myself.
> In fact, the _save_FIELD_file method (not save_avatar_file) is
> automatically called when I save a UserProfile object in the admin
> interface, or using a custom form generated by form_for_instance.
>
> Any idea?
>
> On Dec 10, 11:53 pm, Thomas <[EMAIL PROTECTED]> wrote:
>
> > I saw something similar with overridden  save(). How/where do you call
> > it?
>
> > Thomas
>
> > On Dec 10, 1:46 pm, Julien <[EMAIL PROTECTED]> wrote:
>
> > > Hi all,
>
> > > I'm struggling to understand why, when I upload an image field (either
> > > from the admin interface or from a custom view), the overriden
> > > save_FOO_file method is never called.
>
> > > In the following example, the "save_avatar_file" method is never
> > > called. However the "_save_FIELD_file" method is called.
> > > It looks a bit dirty to me, and I'd like to get rid of the
> > > "_save_FIELD_file method", to only use a method for a given field (in
> > > this case, "save_avatar_file").
>
> > > Do you know why it's not working as expected?
>
> > > class UserProfile(models.Model):
> > > user = models.ForeignKey(User, unique=True)
> > > avatar = models.ImageField(upload_to='/', null=True)
> > > def _save_FIELD_file(self, field, filename, raw_contents, save):
> > > if field.attname == 'avatar':
> > > image = Image.open(StringIO.StringIO(raw_contents))
> > > self.avatar = '%s.%s' % (self.user.id,
> > > image.format.lower())
> > > filename = settings.PROFILE_AVATAR_UPLOAD_DIR +
> > > self.avatar
> > > image.save(filename)
> > > if save:
> > > self.save()
> > > def save_avatar_file(self, filename, raw_contents, save):
> > > image = Image.open(StringIO.StringIO(raw_contents))
> > > self.avatar = '%s.%s' % (self.user.id, image.format.lower())
> > > filename = settings.PROFILE_AVATAR_UPLOAD_DIR + self.avatar
> > > image.save(filename)
> > > if save:
> > > self.save()
>
> > > Cheers,
>
> > > Julien
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField file naming

2007-11-30 Thread Marty Alchin
I don't have a definitive answer at this point, no. Everybody who
wants some form of flexible file naming has a different need, and it's
tough to come up with something that pleases everyone, while still
being a fairly concise API. I've been giving it some thought, and I'll
make sure to bring it up during the sprint, but I don't know what will
come of it.

I'm hoping to get the rest of my FileField changes in this weekend,
and while I'd like to solve this problem along with it, it's not a
showstopper in terms of getting the rest of it in.

So the short story is, I'll do what I can, but as always, if you have
some code that does what you'd like, it'll go a long way toward
figuring out how best to handle it.

-Gul

On 11/30/07, Chris Hoeppner <[EMAIL PROTECTED]> wrote:
>
> I guess you don't have a hint for me to get this working? It seems like
> everyone's having that rename issue where _get_pk returns none. I'm just
> blind-guessing, but perhaps the way to go might be "moving" the file on
> post_save onto another name, since pre_save doesn't provide a pk value?
>
> I don't know the Django internals good enough to solve this myself,
> though I need to get this done ASAP. In a previous project I "solved"
> this with some really ugly workarounds, that my client has to take care
> of constantly, and I wouldn't like to do the same this time.
>
> Of course, the best solution would be including this functionality in
> the django core, since everything else is bound to get obsolete sooner
> or later, and most people wouldn't bother updating this to keep it up
> with the trunk.
>
> I've gone trough the links below, and got some of it working, but the pk
> thing doesn't work on any of them.
>
> Any help, please?
>
> ~ Chris
>
> El mar, 20-11-2007 a las 15:41 -0500, Marty Alchin escribi�:
> > On Nov 20, 2007 3:33 PM, Chris Hoeppner <[EMAIL PROTECTED]> wrote:
> > > It would be nice to be able to include this in the upload_to parameter.
> > > Something like
> > > 'upload/%(model_name)s/%(instance_id)s.%(mimetype_extension)s' perhaps?
> > > Maybe, if the parameter ends with a slash, the handler could know "ok.
> > > this is a directory. let's keep the original filename".
> >
> > As usual, I'll respond to this as I've been doing a good bit of work
> > in this area lately. There's no "official" way to do this yet, but
> > there are ways to get the job done. Take a look at the links below for
> > more information on some techniques.
> >
> > I'm doing a good bit of work on making Django handle renaming a bit
> > better, and I'm hoping it will land during the next sprint on December
> > 1. There's no guarantee of that, of course, but that's my personal
> > goal. That will be documented thoroughly when it lands, and I'll make
> > an announcement here on django-users whenever that is, sprint or not.
> >
> > -Gul
> >
> > http://scottbarnham.com/blog/2007/07/31/uploading-images-to-a-dynamic-path-with-django/
> > http://code.djangoproject.com/wiki/CustomUploadAndFilters
> > http://gulopine.gamemusic.org/2007/11/customizing-filenames-without-patching.html
> >
> > >
>
>
> >
>

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField file naming

2007-11-30 Thread Chris Hoeppner

I guess you don't have a hint for me to get this working? It seems like
everyone's having that rename issue where _get_pk returns none. I'm just
blind-guessing, but perhaps the way to go might be "moving" the file on
post_save onto another name, since pre_save doesn't provide a pk value?

I don't know the Django internals good enough to solve this myself,
though I need to get this done ASAP. In a previous project I "solved"
this with some really ugly workarounds, that my client has to take care
of constantly, and I wouldn't like to do the same this time.

Of course, the best solution would be including this functionality in
the django core, since everything else is bound to get obsolete sooner
or later, and most people wouldn't bother updating this to keep it up
with the trunk.

I've gone trough the links below, and got some of it working, but the pk
thing doesn't work on any of them.

Any help, please?

~ Chris

El mar, 20-11-2007 a las 15:41 -0500, Marty Alchin escribi�:
> On Nov 20, 2007 3:33 PM, Chris Hoeppner <[EMAIL PROTECTED]> wrote:
> > It would be nice to be able to include this in the upload_to parameter.
> > Something like
> > 'upload/%(model_name)s/%(instance_id)s.%(mimetype_extension)s' perhaps?
> > Maybe, if the parameter ends with a slash, the handler could know "ok.
> > this is a directory. let's keep the original filename".
> 
> As usual, I'll respond to this as I've been doing a good bit of work
> in this area lately. There's no "official" way to do this yet, but
> there are ways to get the job done. Take a look at the links below for
> more information on some techniques.
> 
> I'm doing a good bit of work on making Django handle renaming a bit
> better, and I'm hoping it will land during the next sprint on December
> 1. There's no guarantee of that, of course, but that's my personal
> goal. That will be documented thoroughly when it lands, and I'll make
> an announcement here on django-users whenever that is, sprint or not.
> 
> -Gul
> 
> http://scottbarnham.com/blog/2007/07/31/uploading-images-to-a-dynamic-path-with-django/
> http://code.djangoproject.com/wiki/CustomUploadAndFilters
> http://gulopine.gamemusic.org/2007/11/customizing-filenames-without-patching.html
> 
> > 


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField file naming

2007-11-23 Thread Chris Hoeppner

El mar, 20-11-2007 a las 15:41 -0500, Marty Alchin escribió:
> On Nov 20, 2007 3:33 PM, Chris Hoeppner <[EMAIL PROTECTED]> wrote:
> > It would be nice to be able to include this in the upload_to parameter.
> > Something like
> > 'upload/%(model_name)s/%(instance_id)s.%(mimetype_extension)s' perhaps?
> > Maybe, if the parameter ends with a slash, the handler could know "ok.
> > this is a directory. let's keep the original filename".
> 
> As usual, I'll respond to this as I've been doing a good bit of work
> in this area lately. There's no "official" way to do this yet, but
> there are ways to get the job done. Take a look at the links below for
> more information on some techniques.
> 
> I'm doing a good bit of work on making Django handle renaming a bit
> better, and I'm hoping it will land during the next sprint on December
> 1. There's no guarantee of that, of course, but that's my personal
> goal. That will be documented thoroughly when it lands, and I'll make
> an announcement here on django-users whenever that is, sprint or not.
> 
> -Gul

Not as if this is a "basic" feature, but I think Django *should* or
*might* have builtin support for this kind of things.

Not being able to use instance information is quite limiting, somehow...
But as The Guys say, Python nor Django are to have everyones pet
feature. That's called PHP.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField file naming

2007-11-20 Thread Marty Alchin

On Nov 20, 2007 3:33 PM, Chris Hoeppner <[EMAIL PROTECTED]> wrote:
> It would be nice to be able to include this in the upload_to parameter.
> Something like
> 'upload/%(model_name)s/%(instance_id)s.%(mimetype_extension)s' perhaps?
> Maybe, if the parameter ends with a slash, the handler could know "ok.
> this is a directory. let's keep the original filename".

As usual, I'll respond to this as I've been doing a good bit of work
in this area lately. There's no "official" way to do this yet, but
there are ways to get the job done. Take a look at the links below for
more information on some techniques.

I'm doing a good bit of work on making Django handle renaming a bit
better, and I'm hoping it will land during the next sprint on December
1. There's no guarantee of that, of course, but that's my personal
goal. That will be documented thoroughly when it lands, and I'll make
an announcement here on django-users whenever that is, sprint or not.

-Gul

http://scottbarnham.com/blog/2007/07/31/uploading-images-to-a-dynamic-path-with-django/
http://code.djangoproject.com/wiki/CustomUploadAndFilters
http://gulopine.gamemusic.org/2007/11/customizing-filenames-without-patching.html

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField Validation Error

2007-11-15 Thread Arnold Chen

I faced this problem as well, but there is a work around. I am using
django 0.97 pre (i downloaded from svn 16th Nov, 2007)

Go to c:/python2.4/lib/site-packages/django/core/validators.py
or
/usr/lib/python2.4/site-packages/django/core/validators.py , if you
are using Fedora

comment the following lines (the line numbers in my version is 186 and
187
trial_image = Image.open(StringIO(content))
trial_image.load()

Good luck

On Nov 5, 3:27 am, Matt <[EMAIL PROTECTED]> wrote:
> I've got a model with anImageField. But, when I attempt to add an
> image via the Admin interface, I receive theerrormessage: "Upload a
> valid image. The file you uploaded was either not an image or a
> corrupted image."
>
> I'm pretty sure that all of my paths are set correctly because I can
> change the field to a FileField and add an image without any problems.
> I can also successfully work with the same image field via PIL - so I
> don't think it's not an issue with the actual image file or PIL.
>
> Is this a bug or is there something I'm not doing right? I'm running
> the latest Django from SVN, PIL 1.1.6 and  Python 2.5.1 on OS X 10.5.
> 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField Validation Error

2007-11-12 Thread drackett

I'm running into this exact same issue. Very few images I try are
"valid" even though I can work with them in PIL by hand.

On Nov 4, 1:27 pm, Matt <[EMAIL PROTECTED]> wrote:
> I've got a model with an ImageField. But, when I attempt to add an
> image via the Admin interface, I receive the error message: "Upload a
> valid image. The file you uploaded was either not an image or a
> corrupted image."
>
> I'm pretty sure that all of my paths are set correctly because I can
> change the field to a FileField and add an image without any problems.
> I can also successfully work with the same image field via PIL - so I
> don't think it's not an issue with the actual image file or PIL.
>
> Is this a bug or is there something I'm not doing right? I'm running
> the latest Django from SVN, PIL 1.1.6 and  Python 2.5.1 on OS X 10.5.
> 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField via admin

2007-08-22 Thread Carl Karsten



Grigory Fateyev wrote:
> Hello Carl Karsten!
> On Tue, 21 Aug 2007 10:21:06 -0500 you wrote:
> 
>> Grigory Fateyev wrote:
>>> Hello Carl Karsten!
>>> On Mon, 20 Aug 2007 14:07:39 -0500 you wrote:
>>>
> settings.py:MEDIA_ROOT = BASE_DIR+'/media/'
> settings.py:MEDIA_URL = '/site_media/'
> urls.py:(r'^site_media/(?P.*)$',
> 'django.views.static.serve', {'document_root':
> settings.BASE_DIR+'/media/', 'show_indexes':True}),
>
> Revision: 5946
>   
 I used your settings, no problem.

 Python 2.5.1 (r251:54863, May  2 2007, 16:56:35)

 [EMAIL PROTECTED]:~/django/django_src$ svn up
 Updated to revision 5988.

 Carl K
>>> That means you can add any object to Book class without problem?
>>>
>>> Thanks!
>> yep.  edit too.
>>
>> I suggest making a new site/project, add the model, make the few
>> changes to settings and run the dev server.
>>
>> Carl K
> 
> Very funny, but new project with the only class "Book" return the same
> error:
> 
> Traceback (most recent call last):
> File "/usr/lib/python2.4/site-packages/django/core/handlers/base.py" in
> get_response 77. response = callback(request, *callback_args,
> **callback_kwargs) File
> "/usr/lib/python2.4/site-packages/django/contrib/admin/views/decorators.py"
> in _checklogin 51. if 'post_data' in request.POST: File
> "/usr/lib/python2.4/site-packages/django/core/handlers/wsgi.py" in
> _get_post 136. self._load_post_and_files() File
> "/usr/lib/python2.4/site-packages/django/core/handlers/wsgi.py" in
> _load_post_and_files 114. self._post, self._files =
> http.parse_file_upload(self.environ['wsgi.input'], self.environ) File
> "/usr/lib/python2.4/site-packages/django/http/__init__.py" in
> parse_file_upload 71. raw_message = '\r\n'.join(['%s:%s' % pair for
> pair in header_dict.items()])
> 
>   AttributeError at /admin/books/book/add/
>   '_fileobject' object has no attribute 'items'
> 

do you have access to a python 25 box?

Make sure django is up to date.

Carl K

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField via admin

2007-08-22 Thread Grigory Fateyev

Hello Carl Karsten!
On Tue, 21 Aug 2007 10:21:06 -0500 you wrote:

> 
> Grigory Fateyev wrote:
> > Hello Carl Karsten!
> > On Mon, 20 Aug 2007 14:07:39 -0500 you wrote:
> > 
> >>> settings.py:MEDIA_ROOT = BASE_DIR+'/media/'
> >>> settings.py:MEDIA_URL = '/site_media/'
> >>> urls.py:(r'^site_media/(?P.*)$',
> >>> 'django.views.static.serve', {'document_root':
> >>> settings.BASE_DIR+'/media/', 'show_indexes':True}),
> >>>
> >>> Revision: 5946
> >>>   
> >> I used your settings, no problem.
> >>
> >> Python 2.5.1 (r251:54863, May  2 2007, 16:56:35)
> >>
> >> [EMAIL PROTECTED]:~/django/django_src$ svn up
> >> Updated to revision 5988.
> >>
> >> Carl K
> > 
> > That means you can add any object to Book class without problem?
> > 
> > Thanks!
> 
> yep.  edit too.
> 
> I suggest making a new site/project, add the model, make the few
> changes to settings and run the dev server.
> 
> Carl K

Very funny, but new project with the only class "Book" return the same
error:

Traceback (most recent call last):
File "/usr/lib/python2.4/site-packages/django/core/handlers/base.py" in
get_response 77. response = callback(request, *callback_args,
**callback_kwargs) File
"/usr/lib/python2.4/site-packages/django/contrib/admin/views/decorators.py"
in _checklogin 51. if 'post_data' in request.POST: File
"/usr/lib/python2.4/site-packages/django/core/handlers/wsgi.py" in
_get_post 136. self._load_post_and_files() File
"/usr/lib/python2.4/site-packages/django/core/handlers/wsgi.py" in
_load_post_and_files 114. self._post, self._files =
http.parse_file_upload(self.environ['wsgi.input'], self.environ) File
"/usr/lib/python2.4/site-packages/django/http/__init__.py" in
parse_file_upload 71. raw_message = '\r\n'.join(['%s:%s' % pair for
pair in header_dict.items()])

  AttributeError at /admin/books/book/add/
  '_fileobject' object has no attribute 'items'

-- 
Всего наилучшего! Григорий
greg [at] anastasia [dot] ru
Письмо отправлено: 2007/08/21 20:43

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField via admin

2007-08-21 Thread Grigory Fateyev

Hello Carl Karsten!
On Tue, 21 Aug 2007 10:21:06 -0500 you wrote:

> 
> Grigory Fateyev wrote:
> > Hello Carl Karsten!
> > On Mon, 20 Aug 2007 14:07:39 -0500 you wrote:
> > 
> >>> settings.py:MEDIA_ROOT = BASE_DIR+'/media/'
> >>> settings.py:MEDIA_URL = '/site_media/'
> >>> urls.py:(r'^site_media/(?P.*)$',
> >>> 'django.views.static.serve', {'document_root':
> >>> settings.BASE_DIR+'/media/', 'show_indexes':True}),
> >>>
> >>> Revision: 5946
> >>>   
> >> I used your settings, no problem.
> >>
> >> Python 2.5.1 (r251:54863, May  2 2007, 16:56:35)
> >>
> >> [EMAIL PROTECTED]:~/django/django_src$ svn up
> >> Updated to revision 5988.
> >>
> >> Carl K
> > 
> > That means you can add any object to Book class without problem?
> > 
> > Thanks!
> 
> yep.  edit too.
> 
> I suggest making a new site/project, add the model, make the few
> changes to settings and run the dev server.
> 
> Carl K

Very funny, but new project with the only class "Book" return the same
error:

Traceback (most recent call last):
File "/usr/lib/python2.4/site-packages/django/core/handlers/base.py" in
get_response 77. response = callback(request, *callback_args,
**callback_kwargs) File
"/usr/lib/python2.4/site-packages/django/contrib/admin/views/decorators.py"
in _checklogin 51. if 'post_data' in request.POST: File
"/usr/lib/python2.4/site-packages/django/core/handlers/wsgi.py" in
_get_post 136. self._load_post_and_files() File
"/usr/lib/python2.4/site-packages/django/core/handlers/wsgi.py" in
_load_post_and_files 114. self._post, self._files =
http.parse_file_upload(self.environ['wsgi.input'], self.environ) File
"/usr/lib/python2.4/site-packages/django/http/__init__.py" in
parse_file_upload 71. raw_message = '\r\n'.join(['%s:%s' % pair for
pair in header_dict.items()])

  AttributeError at /admin/books/book/add/
  '_fileobject' object has no attribute 'items'

-- 
Всего наилучшего! Григорий
greg [at] anastasia [dot] ru
Письмо отправлено: 2007/08/21 20:43

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField via admin

2007-08-21 Thread Carl Karsten

Grigory Fateyev wrote:
> Hello Carl Karsten!
> On Mon, 20 Aug 2007 14:07:39 -0500 you wrote:
> 
>>> settings.py:MEDIA_ROOT = BASE_DIR+'/media/'
>>> settings.py:MEDIA_URL = '/site_media/'
>>> urls.py:(r'^site_media/(?P.*)$',
>>> 'django.views.static.serve', {'document_root':
>>> settings.BASE_DIR+'/media/', 'show_indexes':True}),
>>>
>>> Revision: 5946
>>>   
>> I used your settings, no problem.
>>
>> Python 2.5.1 (r251:54863, May  2 2007, 16:56:35)
>>
>> [EMAIL PROTECTED]:~/django/django_src$ svn up
>> Updated to revision 5988.
>>
>> Carl K
> 
> That means you can add any object to Book class without problem?
> 
> Thanks!

yep.  edit too.

I suggest making a new site/project, add the model, make the few changes to 
settings and run the dev server.

Carl K

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



  1   2   >