I am new in Django and i am having trouble on how to configure this error, so that is why i decided to post a question of some of my code, i hope you guys help me on this problem. did i miss or i did wrong in my code? please bear with me. thanks.
Error 'Query' object has no attribute 'contains_column_references'
Traceback:
Traceback:
File "/home/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner 34. response = get_response(request)
File "/home/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response 115. response = self.process_exception_by_middleware(e, request)
File "/home/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response 113. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/unidaweb/unidaproject/Homepage/views.py" in updateperiod 2289. V_insert_data.save()
File "/home/lib/python3.6/site-packages/django/db/models/base.py" in save 741. force_update=force_update, update_fields=update_fields)
File "/home/lib/python3.6/site-packages/django/db/models/base.py" in save_base 779. force_update, using, update_fields,
File "/home/lib/python3.6/site-packages/django/db/models/base.py" in _save_table 870. result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/home/lib/python3.6/site-packages/django/db/models/base.py" in _do_insert 908. using=using, raw=raw)
File "/home/lib/python3.6/site-packages/django/db/models/manager.py" in manager_method 82. return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/lib/python3.6/site-packages/django/db/models/query.py" in _insert 1186. return query.get_compiler(using=using).execute_sql(return_id)
File "/home/lib/python3.6/site-packages/django/db/models/sql/compiler.py" in execute_sql 1334. for sql, params in self.as_sql():
File "/home/lib/python3.6/site-packages/django/db/models/sql/compiler.py" in as_sql 1278. for obj in self.query.objs
File "/home/lib/python3.6/site-packages/django/db/models/sql/compiler.py" in 1278. for obj in self.query.objs
File "/home/lib/python3.6/site-packages/django/db/models/sql/compiler.py" in 1277. [self.prepare_value(field, self.pre_save_val(field, obj)) for field in fields]
File "/home/lib/python3.6/site-packages/django/db/models/sql/compiler.py" in prepare_value 1208. if value.contains_column_references:
Exception Type: AttributeError at /updateperiod/ Exception Value: 'Query' object has no attribute 'contains_column_references'
this is my views.py
id = request.POST.get('id')
if StudentPeriodSummary.objects.filter(id = id).exists():
grade = request.POST.get('average')
update = StudentPeriodSummary.objects.get(id = id)
update.average = grade
update.save()
return render(request, 'Homepage/pending.html')
else:
myperiod = request.POST.get('period')
period = gradingPeriod(id=myperiod)
sectionandgrade = request.POST.get('subjectsection')
gradesSection = SubjectSectionTeacher.objects.filter(id=sectionandgrade).values('Sections')
getsection = Section(id=gradesSection)
gradeslevel = SubjectSectionTeacher.objects.filter(id=sectionandgrade).values('Education_Levels')
grade = EducationLevel(id=gradeslevel)
teacher_id = request.POST.get('teacher')
teacher = EmployeeUser(id=teacher_id)
averages = []
for average in request.POST.getlist('average'):
averages.append(average)
for m, student in enumerate(request.POST.getlist('studentname')):
students = StudentSubjectGrade(id=student)
V_insert_data = StudentPeriodSummary(
teacher=teacher,
students_Enrollment_Records=students,
gradeLevel=grade,
average=averages[m],
grading_Period=period,
sections=getsection,
)
V_insert_data.save()
m += 1
return render(request, 'Homepage/pending.html')
my models.py
class StudentPeriodSummary(models.Model):
teacher = models.ForeignKey(EmployeeUser, null=True, blank=True)
students_Enrollment_Records = models.ForeignKey(StudentSubjectGrade, on_delete=models.CASCADE, null=True)
gradeLevel = models.ForeignKey(EducationLevel,null=True, blank=True)
sections = models.ForeignKey(Section, null=True)
grading_Period = models.ForeignKey(gradingPeriod, null=True, blank=True)
average = models.FloatField(null=True, blank=True)
def __str__(self):
suser = '{0.Students_Enrollment_Records}'
return suser.format(self)
UPDATE
when i tried to comment out the #GradeLevel=grade,
and #Sections=getsection,
in views.py (Inserting data). it works. it seems like from that line is causing the error, what should i do to fix this? is this correct?
gradesSection = SubjectSectionTeacher.objects.filter(id=sectionandgrade).values('Sections')
getsection = Section(id=gradesSection)
gradeslevel = SubjectSectionTeacher.objects.filter(id=sectionandgrade).values('Education_Levels')
grade = EducationLevel(id=gradeslevel)
contains_column_references
? do i have to show my models.py? – user14744011