Monday, March 29, 2021

Re: File Input from User

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

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/20210329164908.GV15054%40fattuba.com.

No comments:

Post a Comment