Моя идея приложения заключается в том, чтобы показывать информацию о врачах клиентам, я использую библиотеку city-light для получения городов, но когда я пытаюсь использовать ее, я получаю ValueError. Вот мой models.py:
from django.db import models
from django.urls import reverse
from phonenumber_field.modelfields import PhoneNumberField
from cities_light.models import City
# Create your models here.
class Doctor(models.Model):
name = models.CharField(max_length=100)
specialty = models.TextField()
address = models.CharField(max_length=250, blank=True)
phone_number = PhoneNumberField(blank=True)
email = models.EmailField(blank=True)
city = models.ForeignKey(City, on_delete=models.CASCADE)
def __str__(self):
return self.name
def get_absolute_url(self):
return reverse('home')
и это HTML-код:
{% extends "base.html" %}
{% load static %}
{% block content %}
{% for doctor in object_list %}
<h1>{{ doctor.name }}</h1>
<p>{{ doctor.specialty }}</p>
<p>{{ doctor.address }}</p>
<p>{{ doctor.phone_number }}</p>
<p>{{ doctor.email }}</p>
<p>{{ doctor.city }}</p>
{% endfor %}
{% endblock content %}
Вот ошибка:
Internal Server Error: /patient/
Traceback (most recent call last):
File "C:\Users\Said\.virtualenvs\mon_psy-XL2vitKu\lib\site-
packages\django\template\base.py", line 829, in _resolve_lookup
current = current[bit]
TypeError: 'Doctor' object is not subscriptable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Said\.virtualenvs\mon_psy-XL2vitKu\lib\site-
packages\django\db\models\fields\related_descriptors.py", line 163, in
__get__
rel_obj = self.field.get_cached_value(instance)
File "C:\Users\Said\.virtualenvs\mon_psy-XL2vitKu\lib\site-
packages\django\db\models\fields\mixins.py", line 13, in get_cached_value
return instance._state.fields_cache[cache_name]
KeyError: 'city'
During handling of the above exception, another exception occurred:
ValueError : invalid literal for int() with base 10: 'sdfs'