Image in Form Field

33 views
Skip to first unread message

Sandeep kaur

unread,
Mar 22, 2015, 5:39:16 AM3/22/15
to django-users
Greetings,
I want to have the thumnails of images with the names in the dropdown field of form. To return the image as foreign key field, I have used  this code :
def __unicode__(self):
        image_data = open("/home/sandy/whats-fresh-api/media/images/download.jpg", "rb").read() 
        return '%s' % (self.name) + HttpResponse(image_data, content_type="image/jpg")

But it give following error :
Exception Value:
coercing to Unicode: need string or buffer, HttpResponse found

Is it possible to do this ?

Thanks.

--

Sandeep kaur

unread,
Mar 23, 2015, 12:51:49 PM3/23/15
to django-users
Anybody please help.

Vijay Khemlani

unread,
Mar 23, 2015, 12:58:23 PM3/23/15
to django...@googlegroups.com
You can't include images in the options of a typycal html dropdown

To do so you need to use JavaScript, for example this plugin


And pass the options in the format specified by the plugin

Anybody please help.
--
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...@googlegroups.com.
To post to this group, send email to django...@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/CAF66xG00kpdSJqW-2D7W_HYR4e%3DVEeW3E81KMHBoU-OhDbUFNA%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages