Форум сайта python.su
Привет!
Помогите, пожалуйста, установить связь
models:
class RegisterUser(models.Model):
username = models.CharField(max_length=50)
email = models.EmailField(max_length=50)
password = models.CharField(max_length=50)
time_create = models.DateTimeField(auto_now_add=True)
class RegisterUserForm(UserCreationForm):
username = forms.CharField(label='Логин', widget=forms.TextInput(attrs={'class': 'form-input'}))
email = forms.EmailField(label='Email', widget=forms.EmailInput(attrs={'class': 'form-input'}))
password1 = forms.CharField(label='Пароль', widget=forms.PasswordInput(attrs={'class': 'form-input'}))
password2 = forms.CharField(label='Повтор пароля', widget=forms.PasswordInput(attrs={'class': 'form-input'}))
captcha = CaptchaField(label='Каптча', widget=CaptchaTextInput(attrs={'class': 'form-input'}))
class Meta:
model = User
fields = ('username', 'email', 'password1', 'password2')
class RegisterUser(CreateView):
form_class = RegisterUserForm
template_name = 'private_site/register.html'
success_url = reverse_lazy('login')
def get_context_data(self, *, object_list=None, **kwargs):
context = super().get_context_data(**kwargs)
context["title"] = "Регистрация"
return context
def form_valid(self, form):
user = form.save()
login(self.request, user)
return redirect('content')
Офлайн
Миграцию сделай
Прочитай про
AbstractUser vs AbstractBaseUser
The default User model in Django uses a username to uniquely identify a user during authentication. If you'd rather use an email address, you'll need to create a custom User model by either subclassing AbstractUser or AbstractBaseUser.
https://testdriven.io/blog/django-custom-user-model/
Офлайн
Спасибо, разобрался
Офлайн