Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. CustomUser(AbstractUser):
  2. password = models.CharField(max_length=200, null=False)
  3. location = models.CharField(max_length=200, blank=True, default="")
  4. description = models.CharField(max_length=300, blank=True, default="")
  5.  
  6. class CustomUserCreationForm(ModelForm):
  7. description = forms.CharField()
  8. location = forms.CharField()
  9. password1 = forms.CharField(label='Password', widget=forms.PasswordInput)
  10. password2 = forms.CharField(label='Password confirmation', widget=forms.PasswordInput)
  11.  
  12. class Meta:
  13. model = CustomUser
  14. fields = ('username', 'email', 'password1', 'password2')
  15.  
  16. class SignUpView(View):
  17. form_class = CustomUserCreationForm
  18. template_name = 'signup.html'
  19.  
  20. def get(self, request):
  21. form = self.form_class()
  22. return render(request, self.template_name, {'form': form})
  23.  
  24. def post(self, request):
  25. form = CustomUserCreationForm(request.POST)
  26. if form.is_valid():
  27. form.save(True)
  28.  
  29. return render(request, self.template_name, {'form': form})
  30.  
  31. class CustomUserAdmin(UserAdmin):
  32. fieldsets = UserAdmin.fieldsets + (('Misc', {'fields': ('description', 'location')}),)
  33. add_fieldsets = UserAdmin.add_fieldsets + (('Misc', {'fields': ('description', 'location')}),)
  34.  
  35.  
  36. admin.site.register(CustomUser, CustomUserAdmin)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement