def __init__(self, post, *args, **kwargs): """Init form with comment's post to set ready for create. Pass None when handling a post method.""" super(CommentForm, self).__init__(*args, **kwargs) if post is not None: self.fields['post'] = forms.ModelChoiceField( queryset=Post.objects.filter(id=post.id), empty_label=None, widget=forms.Select(attrs={'style': 'display:none;'}) ) self.fields['content'] = QuillFormField()
def get_form(self, form_class=None): """Init form by hiding subforum option and leaving current subforum as the only choice.""" form = super(CreatePost, self).get_form(form_class) form.fields['subforum'] = forms.ModelChoiceField( queryset=Subforum.objects.filter(pk=self.subforum.id), empty_label=None, label='', widget=forms.Select(attrs={ 'class': 'form-control', 'style': 'display:none;' })) form.fields['title'].label = _('Title') form.fields['title'].widget = forms.TextInput(attrs={ 'class': 'form-control my-2', 'placeholder': _('Title') }) form.fields['content'] = QuillFormField() form.fields['content'].label = _('Content') return form
class QuillFieldForm(forms.Form): content = QuillFormField()
class QuillFieldForm(forms.Form): body = QuillFormField()
class NewPost(forms.Form): content = QuillFormField()
class QuillFieldForm(forms.Form): content = QuillFormField() def save(self): return QuillPost.objects.create(content=self.cleaned_data['content'])
class QuillForm(forms.Form): quill = QuillFormField()