Не могу понять в чем ошибка:confirmation_code = ConfirmationCode(user=user, code=code)?
models.py:
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.contrib.auth.models import User
class UserCreationForm(models.Model):
name = models.CharField('Имя', max_length=50)
surname = models.CharField('Фамилия', max_length=50)
def __str__(self):
return self.name
class Meta:
verbose_name = 'Ученики'
verbose_name_plural = 'Ученики'
class TableBase(models.Model):
name = models.CharField('Имя', max_length=50)
surname = models.CharField('Фамилия', max_length=50)
def __str__(self):
return self.name
class Meta:
verbose_name = 'Ученики'
verbose_name_plural = 'Ученики'
class User(AbstractUser):
pass
class Person(models.Model):
name = models.CharField(max_length=20)
age = models.IntegerField()
class User(models.Model):
name = models.CharField('Имя', max_length=50)
surname = models.CharField('Фамилия', max_length=50)
class ConfirmationCode(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
code = models.CharField(max_length=4)
def __str__(self):
return self.code
forms.py:
from django import forms
from django.contrib.auth.forms import UserCreationForm as BaseUserCreationForm
from django.contrib.auth.models import User
from django import forms
class UserCreationForm(BaseUserCreationForm):
class Meta:
model = User
fields = ('username', 'password1', 'password2')
class RegistrationForm(forms.ModelForm):
class Meta:
model = User
fields = ['username', 'password', 'email']
views.py:
import sqlite3
from django.views.generic import ListView
from django.contrib.auth.models import User
from django.shortcuts import render, redirect
from django.contrib import messages
from django.contrib.auth import authenticate, login
from .forms import RegistrationForm
from .models import ConfirmationCode
import secrets