You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
TeamFlash/sahara/main/forms.py

79 lines
2.7 KiB

from django import forms
6 months ago
from django.contrib.auth.forms import AuthenticationForm
from .models import User
from django import forms
from .models import User, Service
6 months ago
class UserRegistrationForm(forms.ModelForm):
# Password and confirm password fields with custom classes
6 months ago
password = forms.CharField(
widget=forms.PasswordInput(attrs={
'class': 'form-control',
'placeholder': 'Enter your password',
})
)
6 months ago
confirm_password = forms.CharField(
widget=forms.PasswordInput(attrs={
'class': 'form-control',
'placeholder': 'Confirm your password',
})
)
6 months ago
class Meta:
model = User
fields = ['email', 'first_name', 'last_name', 'profile', 'price', 'bio', 'service_offered', 'login_profile']
6 months ago
widgets = {
'first_name': forms.TextInput(attrs={
'class': 'form-control',
'placeholder': 'Enter your first name',
}),
'last_name': forms.TextInput(attrs={
'class': 'form-control',
'placeholder': 'Enter your last name',
}),
'email': forms.EmailInput(attrs={
'class': 'form-control',
'placeholder': 'Enter your email address',
}),
'profile': forms.ClearableFileInput(attrs={
'class': 'form-control',
'placeholder': 'Upload your profile image',
}),
'bio': forms.Textarea(attrs={
'class': 'form-control',
'placeholder': 'Enter your bio',
'rows': 4, # You can customize the rows and columns as needed
}),
'price': forms.NumberInput(attrs={
'class': 'form-control',
'placeholder': 'Enter your price',
}),
'service_offered': forms.Select(attrs={
'class': 'form-control',
}),
'login_profile': forms.Select(attrs={
'class': 'form-control',
}),
6 months ago
}
def clean(self):
cleaned_data = super().clean()
password = cleaned_data.get('password')
confirm_password = cleaned_data.get('confirm_password')
# Check if passwords match
if password != confirm_password:
self.add_error('confirm_password', 'Passwords do not match')
return cleaned_data
6 months ago
def clean(self):
cleaned_data = super().clean()
password = cleaned_data.get('password')
confirm_password = cleaned_data.get('confirm_password')
6 months ago
if password and confirm_password and password != confirm_password:
raise forms.ValidationError("Passwords do not match.")