21 lines
652 B
Python
21 lines
652 B
Python
from django import forms
|
|
from django.contrib.auth.forms import UserCreationForm
|
|
from .models import User
|
|
|
|
class CitizenRegistrationForm(UserCreationForm):
|
|
email = forms.EmailField(required=True)
|
|
phone = forms.CharField(max_length=15, required=False)
|
|
|
|
class Meta:
|
|
model = User
|
|
fields = ['username', 'email', 'phone', 'password1', 'password2']
|
|
|
|
def save(self, commit=True):
|
|
user = super().save(commit=False)
|
|
user.email = self.cleaned_data['email']
|
|
user.phone = self.cleaned_data['phone']
|
|
user.is_citizen = True
|
|
|
|
if commit:
|
|
user.save()
|
|
return user |