'列表'对象没有属性' _meta'?

时间:2016-03-02 23:44:38

标签: django forms python-2.7 templates meta

我正在为一家医疗公司做一个CRUD,我试图从某个医生那里展示专业,但当他们有多个时我试图将这个对象作为一个列表(我得到它)

但是当我尝试将其传递给模板时,它会失败,我该怎么办?

这是我的观点

def UpdatePhysician(request,id):

physician = get_object_or_404(Physician, id=id)
employee = get_object_or_404(Employee, id=physician.employee.id)
person = get_object_or_404(Person, id=employee.person.id)
try:
    address = get_object_or_404(Address, id=return_id(str(person.addresses.values('id'))))
except:
    address = None
try:
    email = get_object_or_404(Email, id=return_id(str(person.emails.values('id'))))
except:
    email = None
try:
    phone = get_object_or_404(PhoneNumber, id=return_id(str(person.phone_numbers.values('id'))))
except:
    phone = None
try:
    academic_degree = get_object_or_404(AcademicDegree, id=return_id(str(employee.academic_degrees.values('id'))))
    university = get_object_or_404(University, id=return_id(str(employee.academic_degrees.values('university'))))
except:
    academic_degree = None
    university = None
physician_specialties = get_list_or_404(PhysicianSpecialties, employee_academic_degree__employee__pk=physician.employee.id)
for item in physician_specialties:
    print(unicode(item.specialty))
physician_specialties_form = PhysicianSpecialtiesForm(request.POST or None, instance=physician_specialties)
specialties = Specialty.objects.all()
specialty = PhysicianSpecialties.objects.filter(employee_academic_degree__employee__physician__pk=id)
academic_degree = EmployeeAcademicDegree.objects.filter(employee__physician__pk=id)

person_form = PersonForm(request.POST or None, instance=person)
employee_form = EmployeeForm(request.POST or None, instance=employee)
physician_form = PhysicianForm(request.POST or None, instance=physician)
email_form = EmailForm(request.POST or None, instance=email)
address_form = AddressForm(request.POST or None, instance=address)
phone_form = PhoneForm(request.POST or None, instance=phone)
academic_degree_form = AcademicDegreeForm(request.POST or None, instance= academic_degree)
university_form = UniversityForm(request.POST or None, instance=university)


if (person_form.is_valid() and employee_form.is_valid() and physician_form.is_valid() and email_form.is_valid() and
        address_form.is_valid() and phone_form.is_valid and physician_form.is_valid() and university_form.is_valid and
        academic_degree_form.is_valid()):
    person_form.save()
    physician_form.save()
    academic_degree_form.save()
    new_address = address_form.save()
    new_email = email_form.save()
    new_phone = phone_form.save()
    university_form.save()

    if address == None:
        PersonAddress.objects.create(person=person, address=new_address)

    if email == None:
        PersonEmail.object.create(person=person, email=new_email)

    if phone == None:
        PersonPhoneNumber.objects.create(person=person, hone_number=new_phone)

    return HttpResponse('yesh')

return render(request, 'UpdatePhysician.html', {'person_form': person_form,
                                                'employee_form': employee_form,
                                                'email_form': email_form,
                                                'phone_form': phone_form,
                                                'address_form': address_form,
                                                'physician_form': physician_form,
                                                'specialty': specialty,
                                                'academic_degree_form': academic_degree_form,
                                                'academic_degree': academic_degree,
                                                'university_form':university_form,
                                                'specialties': specialties,
                                                'physician_specialties_form': physician_specialties_form,
                                                })

问题存在于

physician_specialties = get_list_or_404(PhysicianSpecialties, employee_academic_degree__employee__pk=physician.employee.id)
for item in physician_specialties:
    print(unicode(item.specialty))
physician_specialties_form = PhysicianSpecialtiesForm(request.POST or None, instance=physician_specialties)

0 个答案:

没有答案