Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating forms with multiple input types

I am trying to create an input form field which can take text, images or videos as we see in Twitter.

I am trying the following:

from django import forms
from .models import Tweet

class TweetModelForm(forms.ModelForm):
    content = forms.CharField(label='',
                widget=forms.Textarea(
                        attrs={'placeholder': "Your message",
                            "class": "form-control"}
                    ))

Which produces enter image description here

However, I am trying to use the same input box so that user can upload image, video, GIFs or just type text in the box. I am not sure how to modify the above form field.

Edit: If it is not possible using Django, can this be done using HTML5?

like image 862
Zanam Avatar asked Oct 26 '25 00:10

Zanam


1 Answers

enter image description here

You should use a WYSIWYG Editor for that like Froala Editor

Usage

from django import forms
from froala_editor.widgets import FroalaEditor

 class PageForm(forms.ModelForm):
     content = forms.CharField(widget=FroalaEditor)
like image 194
Jeffrey Chidi Avatar answered Oct 28 '25 17:10

Jeffrey Chidi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!