Re: Populating an ImageField

2009-10-03 Thread Nan
Thanks. For a simpler case than what I'm dealing with, yes, that would probably work. On Oct 3, 2:21 pm, kmike wrote: > If you have one default logo then maybe the 'right' way is to use > 'default' parameter of ImageField? > > On 3 окт, 22:07, Nan wrote: > > > Nope, but I finally found what s

Re: Populating an ImageField

2009-10-03 Thread kmike
If you have one default logo then maybe the 'right' way is to use 'default' parameter of ImageField? On 3 окт, 22:07, Nan wrote: > Nope, but I finally found what seems to be the "right" way to do this > (copies the file to the appropriate upload_to location, etc): > > from django.core.files.base

Re: Populating an ImageField

2009-10-03 Thread Nan
Nope, but I finally found what seems to be the "right" way to do this (copies the file to the appropriate upload_to location, etc): from django.core.files.base import File def create_a_company(name, logo_path): company = Company() company.name = name logo_file = open(logo_path) c

Re: Populating an ImageField

2009-10-02 Thread akonsu
did you try company.logo = relative_path ? On Oct 2, 4:45 pm, Nan wrote: > OK, this seemed to work: > > def create_a_company(name, logo_path): >     company = Company() >     company.name = name >     relative_path = path_relative_to_media_root(logo_path) >     company.logo.name = relative_pat

Re: Populating an ImageField

2009-10-02 Thread Nan
OK, this seemed to work: def create_a_company(name, logo_path): company = Company() company.name = name relative_path = path_relative_to_media_root(logo_path) company.logo.name = relative_path company.save() Thank you! On Oct 2, 4:32 pm, Nan wrote: > I tried this, but it'

Re: Populating an ImageField

2009-10-02 Thread Nan
I tried this, but it's just throwing an AttributeError ("can't set sttribute"): def create_a_company(name, logo_path): company = Company() company.name = name logo_url = image_url_from_path(logo_path) company.logo.url = logo_url company.save() On Oct 2, 4:15 pm, akonsu wro

Re: Populating an ImageField

2009-10-02 Thread akonsu
hello, try setting the logo.url property. i do it with FileFields all the time and it works. konstantin On Oct 2, 4:12 pm, ringemup wrote: > Say I have an image file on disk and a model that uses an ImageField. > If I want to create a model instance with that image file in the image > field wi

Populating an ImageField

2009-10-02 Thread ringemup
Say I have an image file on disk and a model that uses an ImageField. If I want to create a model instance with that image file in the image field without explicitly running through a form and a POST operation, how could that be done? Example of what I'm trying to accomplish: class Company(model

Populating an ImageField from an url

2009-04-27 Thread Fabien
Hello, I'm trying to populate an ImageField with the content of an image from it's url. I'm trying with the following code : --- # image_uri is the URL of my image # new_photo.photo is the ImageField field of my new_photo instance current_file = File(urllib.urlopen(image_uri)) current_fi