Advertisement
Guest User

Untitled

a guest
Feb 14th, 2017
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. class RegisterForm(forms.ModelForm):
  2. Gebruikersnaam = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Gebruikersnaam'}), max_length=20, label="")
  3. Wachtwoord = forms.CharField(widget=forms.PasswordInput(attrs={'placeholder': 'Wachtwoord'}), label="")
  4. Emailadres = forms.EmailField(required=False, widget=forms.TextInput(attrs={'placeholder': 'E-mailadres'}), label="")
  5. Profielfoto = forms.ImageField(required=False, label="")
  6. Biografie = forms.CharField(required=False, widget=forms.TextInput(attrs={'placeholder': 'Biografie'}), max_length=150, label="")
  7.  
  8. class Meta:
  9. model = Profiel
  10. fields = ['Gebruikersnaam', 'Wachtwoord', 'Emailadres', 'Profielfoto', 'Biografie']
  11.  
  12. class Profiel(models.Model):
  13. user = models.OneToOneField(User, primary_key=True)
  14. Profielfoto = models.ImageField()
  15. Biografie = models.CharField(max_length=150)
  16.  
  17. def step3(request):
  18.  
  19. if request.method == 'POST':
  20. form = RegisterForm(request.POST)
  21. if form.is_valid():
  22. Registratieform = form.save(commit=False)
  23. username = form.cleaned_data['Gebruikersnaam']
  24. password = form.cleaned_data['Wachtwoord']
  25. user = authenticate(username=username, password=password)
  26.  
  27. Registratieform.user = request.user # Set the user object here
  28. Registratieform.save() # Now you can send it to DB
  29. if Registratieform.user is not None:
  30. if Registratieform.user.is_active:
  31. login(request, Registratieform.user)
  32. return redirect('/Dashboard/')
  33.  
  34. return render_to_response("Home/index.html", {'form': form})
  35. else:
  36. form = RegisterForm()
  37. return render(request, 'Home/index.html', {'form': form})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement