I am trying to generate a query for which I get the expected result in django shell, but for the same query, I am getting an error that the attribute for the model does not exist.
First the shell:
>>> from dbaccess.models import *
>>> applicantObject = Applicant.objects.get(pk=5)
>>> vol = VolInterview.objects.get(applicant=applicantObject)
>>> vol
<VolInterview: Rajon>
From views.py
from models import *
def addIntCandidate(request):
applicants = Applicant.objects.filter(applicationStatus="Pending")
interviews = Interview.objects.all()
message = []
if request.method == 'POST':
applicant = request.POST.get('applicant')
...
# the value of applicant at this point is 5
applicantObject = Applicant.objects.get(pk=applicant)
prevRejected = VolInterview.objects.get(applicant=applicantObject)
...
Error message:
type object 'VolInterview' has no attribute 'objects'
Traceback:
E:\projects_directory\djangoprojects\kpr-admin-db\dbaccess\views.py in addIntCandidate
prevRejected = VolInterview.objects.get(applicant=applicantObject)
What am I doing wrong?
It looks like you have replaced VolInterview
with a different class in your views.
To check, you can add print(VolInterview)
to your view and the shell, and check that you get the same result in both.
In Django, it is common to use Form
as a suffix for your form classes, e.g. VolInterviewForm
, so that the model and form names do not clash.