class Meta: model=News # fields='__all__' fields = ['title','content','is_published','category'] widgets={ 'title':forms.TextInput(attrs={'class':'form-control'}), 'text': forms.TextArea(attrs={'class': 'form-control','rows':5}), 'category': forms.Select(attrs={'class': 'form-control'}),
class JobForm(forms.ModelForm): details = forms.CharField( label='Details', widget=forms.TextArea( attrs={'placeholder': 'Enter all details related to Job'} ) )
class Meta(): model = Post fields = ('author', 'title', 'text') widgets = { 'title': forms.TextInput(attrs={'class':'textinputclass'}), 'text': forms.TextArea(attrs={'class':'editable medium-editor-textarea postcontent'}) }
class Meta(): model = Comment fields = ('author', 'text') widgets = { 'author': forms.TextInput(attrs={'class':'textinputclass'}), 'text': forms.TextArea(attrs={'class':'editable medium-editor-textarea'}) }
class Meta(): model = Post fields = ('author','title','text') widgets = { 'title':forms.TextInput(attrs={'class':'textinputclass'}) #class here is a css styling class..out class 'text':forms.TextArea(attrs={'class': 'editable medium-editor-textarea postcontent'}) #editable-we edit it(comes from medium editor library) # 2nd for styling # 3rd is our own class }
class ContactForm(forms.Form): your_name = forms.CharField( label='Your name', max_length=100, widgets=forms.TextInput(attrs={'placeholder': 'Name *'})) your_email = forms.EmailField( request.post or None, widgets=forms.TextInput(attrs={'placeholder': 'Email *'})) your_subject = forms.CharField( label='Your subject', max_length=100, widgets=forms.TextInput(attrs={'placeholder': 'Subject '})) your_comment = forms.CharField( label='Your comment', max_lenght=200, widgets=forms.TextArea(attrs={'placeholder': 'Comments *'})) #required=False,
class ContactForm(forms.form): name = forms.CharField(label='name') email = forms.EmailField(label='e-mail') subject = forms.CharField(label='subject') message = forms.CharField(label='message', widget=forms.TextArea()) def send_mail(self): name = self.cleaned_data['name'] email = self.cleaned_data['email'] subject = self.cleaned_data['subject'] message = self.cleaned_data['message'] content = f'Name: {name} \n E-mai: {email} \n Subject: {subject} \n Message: {message}' mail = EmailMessage(subject='E-mail sent by the System', body=content, from_email='*****@*****.**', to=['*****@*****.**'], headers={'Reply-to:email'}) mail.send()
class Meta: model = Comment fields = ['content', 'image', 'comments', 'parent'] widgets = {'content': forms.TextArea(attrs={'col': 80})}