-
Notifications
You must be signed in to change notification settings - Fork 30
/
forms.py
27 lines (21 loc) 路 863 Bytes
/
forms.py
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
import uuid
from django import forms
from .models import Feedback, FOUND_USEFUL_CHOICES, VOTE_CHOICES
class FeedbackForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(FeedbackForm, self).__init__(*args, **kwargs)
hashed_token = hash(uuid.uuid4().hex)
self.fields["token"].initial = hashed_token
class Meta:
model = Feedback
fields = ["found_useful", "sources", "vote", "comments", "source_url"]
found_useful = forms.ChoiceField(
choices=FOUND_USEFUL_CHOICES,
widget=forms.RadioSelect(attrs={"data-toggle": "button"}),
)
vote = forms.ChoiceField(
choices=VOTE_CHOICES,
widget=forms.RadioSelect(attrs={"data-toggle": "button"}),
)
source_url = forms.CharField(widget=forms.HiddenInput())
token = forms.CharField(widget=forms.HiddenInput())