elif request.method == 'POST':
alphabet = string.ascii_letters + string.digits
#leader_name = request.POST.get('team_cordinator_name').split(' ')
leader_name = request.POST.get('team_cordinator_name')
leader_fname, leader_lname = name_checker(leader_name)
#leader_fname = leader_name[0]
# if len(leader_name) > 1:
# leader_lname = leader_name[1]
ppUser = PolicyPortalUser2020.objects.create(
fname = leader_fname,
lname = leader_lname,
email = request.POST.get('team_cordinator_email'),
password = ''.join(secrets.choice(alphabet) for i in range(20)),
is_PP_user = True,
)
teacherObj = Teacher2020.objects.create(
name = request.POST.get('teacher_name').split(' ', 1),
school = request.POST.get('teacher_name'),
mobile_no = request.POST.get('teacher_mobile'),
email = request.POST.get('teacher_email'),
)
try:
if request.POST.get('org_type') == 'school':
max_team_id = Team2020.objects.filter(team_id__contains='2020IRSCPOLICYS').aggregate(Max('team_id'))
else:
max_team_id = Team2020.objects.exclude(team_id__contains='2020IRSCPOLICYS').aggregate(Max('team_id'))
except:
if request.POST.get('org_type') == 'school':
max_team_id = '2020IRSCPOLICYS001'
else:
max_team_id = '2020IRSCPOLICY001'
max_team_id = int(max_team_id[-3:]) + 1
if request.POST.get('org_type') == 'school':
max_team_id = '2020IRSCPOLICYS' + str(max_team_id)
else:
max_team_id = '2020IRSCPOLICY' + str(max_team_id)
tObj = Team2020.objects.create(
team_id = max_team_id,
tname=request.POST.get('team_name'),
institute = request.POST.get('institute'),
pUser = ppUser,
teacher = teacherObj,
city = request.POST.get('city'),
state = request.POST.get('state'),
#is_school = request.POST.get('school'), shall we use these fields to identify
#is_college = request.POST.get('college'),
)
класс Team2020 (models.Model):
pUser = models.OneToOneField(PolicyPortalUser2020,on_delete=models.CASCADE,blank=True,null=True)
phase = models.ForeignKey(Phase2020,on_delete=models.DO_NOTHING,blank=True,null=True)
teacher = models.ForeignKey(Teacher2020,on_delete=models.DO_NOTHING,blank=True,null=True)
notifications = models.ManyToManyField(Notifications2020,blank=True,)
is_offer_generated = models.BooleanField(default=False)
id = models.IntegerField(null=True,blank=True)
team_id = models.CharField(primary_key=True,max_length=30,)
tname = models.TextField()
city = models.CharField(max_length = 40, null = True, blank = True)
state = models.TextField()
is_member_registered = models.BooleanField(default=False)
max_members = models.IntegerField(default=4)
total_score = models.IntegerField(default=0)
phase_deadline = models.DateTimeField(null=True)
phase_completed = models.BooleanField(default=False)
mentor = models.ForeignKey(Mentor2020,on_delete=models.DO_NOTHING,blank = True, null = True)
#is_school = models.BooleanField(default=False)
#is_college = models.BooleanField(default=False)
institute = models.TextField(default=None)
def __str__(self):
return self.tname
Поскольку views.py выдает ошибку, когда я запускаю ее и отправляю форму для получения пользовательских вводимых данных. Существует несоответствие в база данных как вставка team_max_id. Это исключение возникает при попытке использования моделей до завершения процесса загрузки приложения, который инициализирует ORM. Я создаю форму пользователя и обновляю ее для группы моделей2020