在创建并验证用户身份后,我使用Query.distinct()
内容保存模型对象。
问题是我的用户已创建并通过身份验证,但是扩展模型的原因在于,在没有给出错误的情况下,数据库中的非常用户信息request.POST
无法保存。这是我的代码:
"school_info model"
school_info模型
@api_view(['POST'])
@permission_classes((permissions.AllowAny, ))
def login_api(request):
post = request.POST
user = authenticate(
request,
username=request.POST['username'],
password=request.POST['password']
)
if user:
school = school_info.objects.create(
school_user=request.user,
school_name=post['school_name'],
school_manager_name=post['school_manager_name'],
school_manager_phone=post['school_manager_phone'],
class_count=post['class_count'],
students_per_class=post['students_per_class'],
daytime_importance=post['daytime_importance'],
)
school = school.save()
login(request, user)
return Response({}, status=200)
else:
return Response({}, status=401)
我也尝试过class school_info(models.Model):
school_user = models.OneToOneField(User, on_delete=models.CASCADE)
school_name = models.CharField(max_length=20)
school_manager_name = models.CharField(max_length=20)
school_manager_phone = models.CharField(max_length=11)
class_count = models.IntegerField()
students_per_class = models.IntegerField()
daytime_importance = models.BooleanField(default=False)
和ModelForms
,但它们都不起作用。
任何答案将不胜感激。