Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class EmployerUser(models.Model):
- id = models.AutoField(primary_key=True)
- user = models.ForeignKey(User,on_delete=models.CASCADE)
- company_name = models.CharField(max_length=20,default="")
- address = models.TextField(default="")
- industry = models.CharField(choices=INDUSTRY,max_length=20,default="")
- isSalarySacrifies = models.CharField(max_length=20,choices=SALARYSACRIFIES,default=False)
- isNetpayRelief = models.CharField(max_length=20,choices=NETPAY,default=False)
- contribution_type = models.CharField(choices=CONTRI_TYPE,max_length=20,default="")
- contribution_change_type = models.CharField(choices=CONTRI_CHANGE_TYPE,max_length=20,default="")
- payrise_type = models.CharField(choices=PAYRISE,max_length=20,default="")
- bonus_type = models.CharField(choices=BONUS,max_length=20,default="")
- def __str__(self):
- return self.company_name
- def register_view(request):
- form = UserRegisterForm(request.POST or None)
- profileform = EmployerUserForm(request.POST or None)
- if form.is_valid() and profileform.is_valid():
- user = form.save(commit=False)
- password = form.cleaned_data.get('password')
- user.set_password(password)
- user.save()
- profile = profileform.save(commit=False)
- profile.save()
- # messages.success(self.request, 'Register Successfully')
- return redirect('login')
- context = {
- 'form': form,
- 'profileform': profileform,
- }
- return render(request, "registration/signup.html", context)
- class UserRegisterForm(forms.ModelForm):
- first_name = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'First Name'}))
- last_name = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Last Name'}))
- email = forms.EmailField(widget=forms.TextInput(attrs={'placeholder': 'Email'}))
- password = forms.CharField(widget=forms.PasswordInput(attrs={'placeholder': 'Password'}))
- mobile = forms.IntegerField(widget=forms.TextInput(attrs={'placeholder': 'Mobile'}))
- class Meta:
- model = User
- fields = [
- 'first_name',
- 'last_name',
- 'mobile',
- 'email',
- 'password'
- ]
- def clean(self, *args, **kwargs):
- email = self.cleaned_data.get('email')
- email_qs = User.objects.filter(email=email)
- if email_qs.exists():
- raise forms.ValidationError(
- "This email has already been registered")
- return super(UserRegisterForm, self).clean(*args, **kwargs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement