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