-
Notifications
You must be signed in to change notification settings - Fork 0
/
forms.py
63 lines (49 loc) · 1.95 KB
/
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from django.contrib.auth.models import User
from .models import Status, SiteUser, Discussion
from django import forms
from . import models
from django.contrib.auth.forms import UserChangeForm
from django.core.validators import RegexValidator
from django.core.exceptions import ValidationError
class UserForm(forms.ModelForm):
GENDER_CHOICES= [
('M', 'M'),
('F', 'F')
]
password = forms.CharField(widget=forms.PasswordInput)
telephone = forms.CharField(max_length=10,min_length=10,validators=[RegexValidator(r'\d{10,10}',
'Enter only 10 digits', 'Invalid telephone number')],help_text='Enter 10 digits only')
gender = forms.CharField(widget=forms.Select(choices=GENDER_CHOICES),help_text='Select either M or F')
birthdate = forms.DateField(help_text='Required Format: YYYY-MM-DD')
class Meta:
model = User
fields = ['username','password','email','first_name','last_name','gender','telephone','birthdate']
help_texts = {
'username': None
}
def __init__(self, *args, **kwargs):
super(UserForm, self).__init__(*args, **kwargs)
self.fields['first_name'].required = True
self.fields['last_name'].required = True
self.fields['telephone'].required = True
self.fields['birthdate'].required = True
class StatusForm(forms.ModelForm):
class Meta:
model = Status
fields = ['text']
widgets = {
'text': forms.TextInput(attrs={
'id': 'post_txt',
'required': True,
'placeholder': 'How are you feeling...',
})
}
class discussionForm(forms.ModelForm):
class Meta:
model = Discussion
fields = ['title', 'content']
class EditProfileForm(forms.ModelForm):
class Meta:
model = User
exclude = ('password','is_staff','is_active','date_joined','groups','user_permissions',
'is_superuser','last_login','username')