Skip to content

Commit 3368461

Browse files
committed
Added users form to handle Institutes, Students, and Faculty members.
1 parent 6f0e68e commit 3368461

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

source/edutravel/users/forms.py

+27-21
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,38 @@
11
from django import forms
2-
from .models import Trip,TripCity,Country,Subdivision,City
2+
from django.db import transaction
3+
from django.contrib.auth.forms import UserCreationForm
34

4-
class TripForm(forms.Form):
5+
from .models import Institute,InstituteType,User
56

6-
country = forms.ModelChoiceField(queryset=Country.objects.all())
7-
state = forms.ModelChoiceField(queryset=Subdivision.objects.all())
8-
#city = forms.ModelChoiceField(queryset=City.objects.all())
7+
class InstituteSignUpForm(UserCreationForm):
98

10-
#class Meta:
11-
# model = Trip
12-
# fields = ('name','country','subdivision','city')
9+
country_address = forms.CharField(max_length=80)
10+
state_address = forms.CharField(max_length=80)
11+
city_address = forms.CharField(max_length=80)
12+
state_address = forms.CharField(max_length=80)
13+
institute_type = forms.ModelChoiceField(
14+
queryset=InstituteType.objects.all()
15+
)
1316

14-
def __init__(self, *args, **kwargs):
15-
super().__init__(*args, **kwargs)
16-
self.fields['state'].queryset = Subdivision.objects.none()
17-
#self.fields['city'].queryset = City.objects.none()
18-
19-
class TravelerForm(forms.Form):
20-
first_name = forms.CharField(max_length=80)
21-
last_name = forms.CharField(max_length=80)
22-
email = forms.EmailField()
23-
passport = forms.CharField(max_length=8)
24-
phone_number = forms.CharField(max_length=12)
17+
class Meta(UserCreationForm.Meta):
18+
model = User
2519

2620
def __init__(self, *args, **kwargs):
27-
super(TravelerForm,self).__init__(*args, **kwargs)
21+
super(InstituteSignUpForm,self).__init__(*args, **kwargs)
2822
for visible in self.visible_fields():
2923
visible.field.widget.attrs['class'] = 'form-control'
3024

31-
25+
@transaction.atomic
26+
def save(self):
27+
user = super().save(commit=False)
28+
user.is_institute = True
29+
user.save()
30+
institute = Institute.objects.create(
31+
user=user,
32+
country_address=self.cleaned_data.get('country_address'),
33+
city_address=self.cleaned_data.get('city_address'),
34+
state_address=self.cleaned_data.get('state_address'),
35+
institute_type=self.cleaned_data.get('institute_type'),
36+
)
37+
return user
3238

0 commit comments

Comments
 (0)