I don't exactly want to save the full path of the image in the
database, just the image extension.  I am trying to convert the
current implementation of a PHP web page to Django.  Here's how the
table looks like, I'll be more explicit with the img ext this time:

id    name      img_ext
-----------------------------
1    Pluto       jpg
2    Scooby   gif

I know in advance that all my pet images will be stored at the
location /usr/django/images/.  So, I can locate the Pluto image with
its unique id.
Pluto: /usr/django/images/1.jpg
Scooby: /usr/django/images/2.gif

I was thinking the best way to do the above is by overriding the save
method.  What I have in mind is:
- Upload the image using ImageField
- Update the column img_ext to the image extension of the above image

The original image upload mechanism might look strange to some but
that's how it is and I am just doing a simple conversion to Django.

On May 6, 2:59 am, Daniel Roseman <roseman.dan...@googlemail.com>
wrote:
> On May 5, 10:15 pm, Thierry <lamthie...@gmail.com> wrote:
>
> > How can I set picture to the image extension?  I don't think
> > "instance.picture = ext" works:
>
> >  def pet_picture_upload(instance, filename):
> >      name, ext = os.path.splitext(filename)
> >      instance.picture = ext
> >      return '/usr/django/images/%s%s' % (instance.pk, ext)
>
> I don't understand what you mean. The value stored in the database for
> 'picture' is the return value of the pet_picture_upload function,
> which is where the picture is stored. It doesn't make sense to set
> 'picture' to just the extension, since there will be no way for Django
> to identify the actual image file. The original code I gave sets
> 'picture' to the value of /usr/django/images/<pk>.ext, which appears
> to be what you want.
>
> If you really want to store the extension separately, you can do that
> - probably also in the pet_picture_upload function, by having a
> separate field for 'ext' and assigning it there, but I don't see why
> you would want to.
> --
> DR.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to