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):
- next = request.GET.get('next')
- 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)
- profile = profileform.save(commit=False)
- password = form.cleaned_data.get('password')
- user.set_password(password)
- user.save()
- profile.save()
- new_user = authenticate(email=user.email, password=password)
- login(request, new_user)
- if next:
- return redirect(next)
- return redirect('login')
- context = {
- 'form': form,
- 'profileform': profileform,
- }
- return render(request, "registration/signup.html", context)
- class EmployerUserForm(ModelForm):
- company_name = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Company Name'}))
- address = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Address'}))
- industry = forms.ChoiceField(choices = INDUSTRY,widget=forms.Select())
- isSalarySacrifies = forms.ChoiceField(choices=SALARYSACRIFIES,widget=forms.RadioSelect())
- isNetpayRelief = forms.ChoiceField(widget=forms.RadioSelect(),choices=NETPAY)
- contribution_type = forms.ChoiceField(label="Contribution Type",choices = CONTRI_TYPE,widget=forms.Select())
- contribution_change_type = forms.ChoiceField(label="Contribution Change Rate Type",choices = CONTRI_CHANGE_TYPE,widget=forms.Select())
- payrise_type = forms.ChoiceField(label="Payrise",choices = PAYRISE,widget=forms.Select())
- bonus_type = forms.ChoiceField(label="Bonus",choices = BONUS,widget=forms.Select())
- class Meta:
- model = EmployerUser
- fields = [
- 'company_name',
- 'address',
- 'industry',
- 'isSalarySacrifies',
- 'isNetpayRelief',
- 'contribution_type',
- 'contribution_change_type',
- 'payrise_type',
- 'bonus_type',
- ]
- profile = profileform.save(commit=False)
- profile.user = user
- profile.save()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement