forms.py 1.26 KB
Newer Older
1
# core django imports
2
from django import forms
3
# third party imports
4
from crispy_forms.helper import FormHelper
Daniel W Bond's avatar
Daniel W Bond committed
5
6
from crispy_forms.layout import Submit, Layout
from crispy_forms.bootstrap import PrependedText, AppendedText
7
8
# imports from your apps
from .models import Student
9

Daniel W Bond's avatar
Daniel W Bond committed
10

11
# form to create student
Daniel W Bond's avatar
Daniel W Bond committed
12
class StudentForm(forms.ModelForm):
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

    def __init__(self, *args, **kwargs):

        self.helper = FormHelper()
        self.helper.layout = Layout(
            'user',
            PrependedText('room', 'Room'),
            'class',
            AppendedText('major', 'Major'),
        )
        self.helper.form_method = 'post'
        self.helper.add_input(Submit('submit', 'Submit'))

        super(StudentForm, self).__init__(*args, **kwargs)

    class Meta:
29
        model = Student
30

31

Daniel W Bond's avatar
Daniel W Bond committed
32
class UserSettingsForm(forms.ModelForm):
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

    def __init__(self, *args, **kwargs):

        self.helper = FormHelper()
        self.helper.layout = Layout(
            'user',
            PrependedText('room', 'Room'),
            'class',
            AppendedText('major', 'Major'),
        )
        self.helper.form_method = 'post'
        self.helper.add_input(Submit('submit', 'Submit'))

        super(StudentForm, self).__init__(*args, **kwargs)

    class Meta:
        model = Student