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?
VolInterviewwith a different class in your views.py? To check, addprint(VolInterview)to your view and the shell, and check that you get the same result.from module import *) in your code - this "feature" should only be used in a Python shell.prevRejected = VolInterview.objects.get(applicant__pk=applicant)(cf docs.djangoproject.com/en/1.9/topics/db/queries/…), though in this case you can just useVolInterview.objects.get(applicant=applicant). But please post new questions as new questions, not as (totally unrelated) comment on this question.