我是巴西人,正在为Google翻译大汗淋漓,我会尽力总结一下,我有一个系统,其中有两个扩展用户的不同用户,我需要使用登录名对其进行区分,但这给了跟随错误 错误: 关系“ sistema_user”不存在 第1行:... r“。” is_student“,” sistema_user“。” is_teacher“来自” sistema_u ...
settings.py dentro precisioni adicionar linha
AUTH_USER_MODEL = 'sistema.User'
models.py
class User(AbstractUser):
is_usuario = models.BooleanField(default=False)
is_negocio = models.BooleanField(default=False)
class Usuario(models.Model):
nome = models.CharField(max_length=50, blank=False)
sobrenome = models.CharField(max_length=50, blank=False)
user = models.OneToOneField(User, on_delete=models.CASCADE)
email_confirmed = models.BooleanField(default=False)
email = models.EmailField(blank=False)
class Negocio(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
empresa = models.CharField(max_length=50, blank=False)
cnpj = models.CharField(max_length=19)
telefone = models.CharField(max_length=20, blank=False)
whatsapp = models.CharField(max_length=20, blank=False)
email = models.EmailField(blank=False)
site = models.CharField(max_length=50, blank=False)
forms.py
class Meta(UserCreationForm.Meta):
model = User
fields = ('username', 'email', 'email2', 'telefone', 'data_nascimento', 'sexo', 'foto',
'endereco', 'numero', 'bairro', 'cidade', 'estado', 'cep', 'pet', 'about')
labels = {
"username": "Nome de usúario"
}
@transaction.atomic
def save(self):
user = super().save(commit=False)
user.usuario = True
user.save()
usuario = Usuario.objects.create(user=user)
usuario.username.add(*self.cleaned_data.get('username'))
return user