Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. class EmployerUser(models.Model):
  2. id = models.AutoField(primary_key=True)
  3. user = models.ForeignKey(User,on_delete=models.CASCADE)
  4. company_name = models.CharField(max_length=20,default="")
  5. address = models.TextField(default="")
  6. industry = models.CharField(choices=INDUSTRY,max_length=20,default="")
  7. isSalarySacrifies = models.CharField(max_length=20,choices=SALARYSACRIFIES,default=False)
  8. isNetpayRelief = models.CharField(max_length=20,choices=NETPAY,default=False)
  9. contribution_type = models.CharField(choices=CONTRI_TYPE,max_length=20,default="")
  10. contribution_change_type = models.CharField(choices=CONTRI_CHANGE_TYPE,max_length=20,default="")
  11. payrise_type = models.CharField(choices=PAYRISE,max_length=20,default="")
  12. bonus_type = models.CharField(choices=BONUS,max_length=20,default="")
  13.  
  14. def __str__(self):
  15. return self.company_name
  16.  
  17. def register_view(request):
  18. next = request.GET.get('next')
  19. form = UserRegisterForm(request.POST or None)
  20. profileform = EmployerUserForm(request.POST or None)
  21.  
  22. if form.is_valid() and profileform.is_valid():
  23. user = form.save(commit=False)
  24. profile = profileform.save(commit=False)
  25. password = form.cleaned_data.get('password')
  26. user.set_password(password)
  27. user.save()
  28. profile.save()
  29. new_user = authenticate(email=user.email, password=password)
  30.  
  31. login(request, new_user)
  32. if next:
  33. return redirect(next)
  34. return redirect('login')
  35.  
  36. context = {
  37. 'form': form,
  38. 'profileform': profileform,
  39. }
  40. return render(request, "registration/signup.html", context)
  41.  
  42. class EmployerUserForm(ModelForm):
  43. company_name = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Company Name'}))
  44. address = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Address'}))
  45. industry = forms.ChoiceField(choices = INDUSTRY,widget=forms.Select())
  46. isSalarySacrifies = forms.ChoiceField(choices=SALARYSACRIFIES,widget=forms.RadioSelect())
  47. isNetpayRelief = forms.ChoiceField(widget=forms.RadioSelect(),choices=NETPAY)
  48. contribution_type = forms.ChoiceField(label="Contribution Type",choices = CONTRI_TYPE,widget=forms.Select())
  49. contribution_change_type = forms.ChoiceField(label="Contribution Change Rate Type",choices = CONTRI_CHANGE_TYPE,widget=forms.Select())
  50. payrise_type = forms.ChoiceField(label="Payrise",choices = PAYRISE,widget=forms.Select())
  51. bonus_type = forms.ChoiceField(label="Bonus",choices = BONUS,widget=forms.Select())
  52. class Meta:
  53. model = EmployerUser
  54. fields = [
  55. 'company_name',
  56. 'address',
  57. 'industry',
  58. 'isSalarySacrifies',
  59. 'isNetpayRelief',
  60. 'contribution_type',
  61. 'contribution_change_type',
  62. 'payrise_type',
  63. 'bonus_type',
  64. ]
  65.  
  66. profile = profileform.save(commit=False)
  67. profile.user = user
  68. profile.save()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement