I have a lot of images for the initial load and want to use a script to get them into the database. When I try to store the image in my Photo model (see the below) I get an error. The funny thing is that I can go on and set the ssi_status, caption and then execute save() and it will store everything to the database. Is this a bug? I'm using the latest svn trunk.
This is what I executed in iPython --------------------------------------------------------------------------- from idms.ssi.models import Photo, SsiStatus from glob import glob folder = r'\\Hiawnt04\ase\GBS\ASE-05390 - SSI List Update for IDMS Testing\Figures\JPEGs' files = glob(folder + '\\*.jpg') photo1 = Photo() photo1.caption = 'SSI diagram' f=files[0] img = open(f,'rb') # now I try to store the image in the model... photo1.save_image_file(f,img) --------------------------------------------------------------------------- exceptions.TypeError Traceback (most recent call last) C:\idms_project\idms\<ipython console> C:\Python24\lib\site-packages\django\db\models\fields\__init__.py in <lambda>(instance, filename, raw_contents) 587 setattr(cls, 'get_%s_url' % self.name, curry(cls._get_FIELD_url, field=self)) 588 setattr(cls, 'get_%s_size' % self.name, curry(cls._get_FIELD_size, field=self)) --> 589 setattr(cls, 'save_%s_file' % self.name, lambda instance, filename, raw_contents: in stance._save_FIELD_file(self, filename, raw_contents)) 590 dispatcher.connect(self.delete_file, signal=signals.post_delete, sender=cls) 591 C:\Python24\lib\site-packages\django\db\models\base.py in _save_FIELD_file(self, field, filename, raw_contents) 346 full_filename = self._get_FIELD_filename(field) 347 fp = open(full_filename, 'wb') --> 348 fp.write(raw_contents) 349 fp.close() 350 TypeError: argument 1 must be string or read-only buffer, not file In [12]: photo1.save_image_file(filename=files[0],raw_content=img) --------------------------------------------------------------------------- exceptions.TypeError Traceback (most recent call last) #then I go on to set the ssi_status etc. photo1.caption="This is a nice Caption" photo1.ssi_status = SsiStatus.objects.get(title__contains="14-1001") photo1.save() # look in the admin and everything is there!?! My model ------------------------------------------------------------------------------- class Photo(models.Model): ssi_status = models.ForeignKey(SsiStatus, edit_inline=True, num_in_admin=2) caption = models.CharField(maxlength=100, core=True) image = models.ImageField(upload_to="ssi", blank=True, null=True) def __str__(self): return self.caption ------------------------------------------------------------------------------- --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---