from django import forms from django.contrib.auth.forms import AuthenticationForm from .models import User from django import forms from .models import User, Service class UserRegistrationForm(forms.ModelForm): # Password and confirm password fields with custom classes password = forms.CharField( widget=forms.PasswordInput(attrs={ 'class': 'form-control', 'placeholder': 'Enter your password', }) ) confirm_password = forms.CharField( widget=forms.PasswordInput(attrs={ 'class': 'form-control', 'placeholder': 'Confirm your password', }) ) class Meta: model = User fields = ['email', 'first_name', 'last_name', 'profile', 'price', 'bio', 'service_offered', 'login_profile'] 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', }), } 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 def clean(self): cleaned_data = super().clean() password = cleaned_data.get('password') confirm_password = cleaned_data.get('confirm_password') if password and confirm_password and password != confirm_password: raise forms.ValidationError("Passwords do not match.")