34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
from .models import CustomUserLogin
|
|
from django.contrib.auth.forms import UserCreationForm
|
|
|
|
class RegisterForm(UserCreationForm):
|
|
class Meta:
|
|
model = CustomUserLogin
|
|
fields = ['username', 'first_name', 'last_name', 'email']
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
|
|
placeholders = {
|
|
'username': 'Choose a unique username',
|
|
'first_name': 'Enter your first name',
|
|
'last_name': 'Enter your last name (optional)',
|
|
'email': 'example@email.com',
|
|
'password1': 'Create a strong password',
|
|
'password2': 'Repeat your password',
|
|
}
|
|
|
|
for field_name, field in self.fields.items():
|
|
|
|
if field_name == 'last_name':
|
|
field.required = False
|
|
else:
|
|
field.required = True
|
|
|
|
if field_name in placeholders:
|
|
field.widget.attrs.update({'placeholder': placeholders[field_name]})
|
|
|
|
field.widget.attrs.update({
|
|
'class': 'form-control mt-2 mb-2',
|
|
'autocomplete': 'off'
|
|
}) |