我正在创建用户名和User_edu之间的关系,这是model.py的双向代码
from django.db import models
class username(models.Model):
name=models.CharField(max_length=100)
class user_edu(models.Model):
qualification=models.CharField(max_length=100)
clgname=models.CharField(max_length=100)
marks=models.CharField(max_length=100)
year_of_graduation=models.CharField(max_length=100)
uname=models.ManyToManyField(username)
在views.py
viewue = user_edu.objects.all()
if request.method == 'POST':
obj = username.objects.get(id=id)
uq = user_edu.objects.get(id=request.POST['qualification'])
uc = user_edu.objects.get(id=request.POST['clgname'])
um = user_edu.objects.get(id=request.POST['marks'])
uy = user_edu.objects.get(id=request.POST['year_of_graduation'])
uq.uname.add(obj)
uc.uname.add(obj)
um.uname.add(obj)
uy.uname.add(obj)
uq.save()
uc.save()
um.save()
uy.save()
return render(request, 'data.html', {'user_edu_all': viewue})
else:
obj = username.objects.get(id=id)
return render(request, 'data.html', {'user_edu_all': viewue})
我正在尝试使用户首先在一个网页中注册该名称,然后在另一页中提供有关教育的详细信息,如何将用户和教育细节相关联