File Input from User

35 views
Skip to first unread message

Kumar Gaurav

unread,
Mar 19, 2021, 2:37:08 AM3/19/21
to Django users
Hi Everyone,

I have a social media kind of portal in Django where user can post an image and write something.
Earlier for image , I used input type=file so that user can select image from there system . But for my requirement, now I want the user to to have an option to either upload or select images from the given set just like selecting some gif's or stickers in social sites. How to do that ?

Please suggest some solution.

Thank You!!

pankaj palmate

unread,
Mar 19, 2021, 2:45:18 AM3/19/21
to django...@googlegroups.com
yes you can do just make one anchor tag and call view asynchronously(using ajax) so that particular set of image is shown and then prepare logic for selecting image and submit the form as you do

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/67527bc4-a297-4161-bad0-0c7450b5c966n%40googlegroups.com.

Kumar Gaurav

unread,
Mar 19, 2021, 3:21:28 AM3/19/21
to Django users
I made one separate table for storing all the image sets and I am able to view it on the template. But while uploading, how to assign it to the post file input, there I am stuck ?? The post image field is configured to get image from the user's system. 

Ryan Nowakowski

unread,
Mar 29, 2021, 12:49:57 PM3/29/21
to Django users
On Thu, Mar 18, 2021 at 11:37:08PM -0700, Kumar Gaurav wrote:
> I have a social media kind of portal in Django where user can post an image
> and write something.
> Earlier for image , I used input type=file so that user can select image
> from there system . But for my requirement, now I want the user to to have
> an option to either upload or select images from the given set just like
> selecting some gif's or stickers in social sites. How to do that ?

1. Add an additional form field that uses RadioSelect[a] to allow the
user to choose an existing image. (Each RadioSelect choice would be an
existing image)
2. Add some form logic[b] that allows the user to either upload a new image
or select an existing image. If both form fields are filled out, raise
a ValidationError

[a] https://stackoverflow.com/a/25216439/226697
[b] https://docs.djangoproject.com/en/3.1/ref/forms/validation/#cleaning-and-validating-fields-that-depend-on-each-other
Reply all
Reply to author
Forward
0 new messages