Я пытаюсь сохранить поле M2M в моей choice
модели. и это дает мне эту ошибку (даже не могу найти, где находится трассировка!
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\fields\related_descriptors.py", line 846
, in __init__
raise ValueError('"%r" needs to have a value for field "%s" before '
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\base.py", line 518, in __repr__
return '<%s: %s>' % (self.__class__.__name__, self)
File "C:\Users\Dell\PycharmProjects\AdmissionSystem\Admission\users\models.py", line 155, in __str__
return self.clg_id
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\fields\related_descriptors.py", line 535
, in __get__
return self.related_manager_cls(instance)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\fields\related_descriptors.py", line 846
, in __init__
raise ValueError('"%r" needs to have a value for field "%s" before '
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\base.py", line 518, in __repr__
return '<%s: %s>' % (self.__class__.__name__, self)
File "C:\Users\Dell\PycharmProjects\AdmissionSystem\Admission\users\models.py", line 155, in __str__
return self.clg_id
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\fields\related_descriptors.py", line 535
, in __get__
return self.related_manager_cls(instance)
RecursionError: maximum recursion depth exceeded
models.py
class choice(models.Model):
stud_id = models.ForeignKey(student, on_delete=models.CASCADE)
clg_id = models.ManyToManyField(college)
created_at = models.DateTimeField(default=timezone.datetime.now())
updated_at = models.DateTimeField(default=timezone.datetime.now())
isactive = models.BooleanField()
def __str__(self):
return self.clg_id
class student(models.Model):
fullname = models.CharField(max_length=50)
password = models.CharField(max_length=10)
email = models.EmailField(unique=True)
class college(models.Model):
name = models.CharField(max_length=50)
password = models.CharField(max_length=10)
, это также дает __str__ return non string type(type student)
ошибка, когда я делаю return self.stud_id
вместо return self.clg_id
Я просто хочу, чтобы каждый студент получал выбор каждого колледжа только один раз. Как сохранить данные в choice
модели?
views.py
def choice_fill(request, cid):
clg = college.objects.all()
title = "Choice Filling"
page = "Choice Filling"
if request.method == "POST":
stud = student.objects.get(id=request.session['id'])
# return render(request, 'success.html',{'stud':stud})
if stud.isactive != 1:
messages.error(request, "Your registration process is incomplete.")
else:
clgid = college.objects.get(id=cid)
# if not choice_filling.objects.filter(clg_id=cid, isactive=1).exists():
if not stud.choice_set.filter(clg_id=cid, isactive=1).exists():
studid = stud.id
c = choice(stud_id_id=studid, isactive=1)
c.clg_id.add(clgid)
c.save()
else:
return HttpResponse('multiple Entry for same college')