-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforms.py
More file actions
36 lines (28 loc) · 1.32 KB
/
Copy pathforms.py
File metadata and controls
36 lines (28 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from django import forms
from pro1.models import Post,Comment
from django.core.validators import MaxValueValidator, MinValueValidator
# Defining the music choices. Tuples given. Pass this into the widgets for the Meta of PostForm.
# Note: The form classes inherit from the ModelForm, which uses the models we created, and specified fields
Music_choices = [('Acoustic','Acoustic'),
('Old School','Old School'),
('Modern Country','Modern Country'),
('Irish Country','Irish Country'),
('Guitar Based','Guitar Based'),
('Other','Other')]
class PostForm(forms.ModelForm):
class Meta():
model = Post
fields = ('author', 'title', 'type','text')
widgets = {
'title':forms.TextInput(attrs={'class':'textinputclass'}),
'text':forms.Textarea(attrs={'class':'editable medium-editor-textarea postcontent'}),
'type':forms.Select(choices=Music_choices) # Pass in list of choices
}
class CommentForm(forms.ModelForm):
class Meta():
model = Comment
fields = ('author','text','rating') # Selected fields.
widgets = {
'author':forms.TextInput(attrs={'class':'textinputclass'}),
'text':forms.Textarea(attrs={'class':'editable medium-editor-textarea'}),
}