moodleNotifer

forms.py
1 from django import forms
2 from .models import Student
3 from django.forms import ModelForm
4 from django.utils.translation import gettext_lazy as _
5
6
7
10 class CreateNewUser(forms.ModelForm):
11 fname = forms.CharField(max_length=200)
12 phone_number = forms.CharField(max_length=10)
13 roll_number = forms.CharField(max_length=9)
14 moodle_token = forms.CharField(max_length=100)
15
16
17
20 class CreateNewUser(ModelForm):
21 class Meta:
22 model = Student
23 fields = [
24 "fname", "phone_number", "roll_number", "moodle_token"
25 ]
26 labels = {
27 'fname': _('Full Name'),
28 'phone_number': _('Phone Number'),
29 'roll_number': _('Roll Number'),
30 'moodle_token': _('Moodle Token'),
31 }
32 help_texts = {
33 'phone_number': _('Enter Your WhatsApp Number.'),
34 'moodle_token': _('Enter Moodle Token Generated'),
35 }
36
37
40 def clean_phone_number(self):
41 phone_number = self.cleaned_data.get('phone_number')
42 if len(phone_number) != 10:
43 raise forms.ValidationError("Invalid Phone Number.")
44 return phone_number
45
46
49 def clean_roll_number(self):
50 roll_number = self.cleaned_data.get('roll_number')
51 if len(roll_number) != 9:
52 raise forms.ValidationError("Invalid Roll Number.")
53 return roll_number
main.forms.CreateNewUser.Meta
Definition: forms.py:21
main.forms.CreateNewUser
This Class is Used for Creating entries, adding labels and helper text in the Registration Page.
Definition: forms.py:10