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