У меня есть таблица (SavedSchedules) ниже в базе данных. В столбцах hall_n_time
и schedule
хранятся два списка python в виде строки.
+----+---------------+-------------+----------+
| id | lecturer | hall_n_time | schedule |
+----+---------------+-------------+----------+
|... | ... | ... | ... |
+----+---------------+-------------+----------+
У меня есть скрипт ниже views.py
:
lec_name = User.objects.filter(username=request.session['logged_username']).values_list('lecturer_name', flat=True)
print(lec_name)
Это дает OUTPUT:
<QuerySet ['A. B. C. Watson']>
Но ОЖИДАЕМЫЙ ВЫХОД:
A. B. C. Watson
Затем я попробовал следующий скрипт:
lec_name = User.objects.filter(username=request.session['logged_username']).values_list('lecturer_name', flat=True)
schedule_data = SavedSchedules.objects.filter(lecturer=lec_name)
print(schedule_data)
Он выдает ОШИБКУ ниже, когда я его выполняю:
Traceback (most recent call last):
File "C:\Users\BhathiyaTK\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\BhathiyaTK\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\BhathiyaTK\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "D:\Web Projects\CIS_ALTG\altg\altg_app\views.py", line 497, in profile
print(schedule_data)
File "C:\Users\BhathiyaTK\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\query.py", line 252, in __repr__
data = list(self[:REPR_OUTPUT_SIZE + 1])
File "C:\Users\BhathiyaTK\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\query.py", line 276, in __iter__
self._fetch_all()
File "C:\Users\BhathiyaTK\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\query.py", line 1261, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "C:\Users\BhathiyaTK\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\query.py", line 57, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "C:\Users\BhathiyaTK\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\sql\compiler.py", line 1124, in execute_sql
sql, params = self.as_sql()
File "C:\Users\BhathiyaTK\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\sql\compiler.py", line 498, in as_sql
where, w_params = self.compile(self.where) if self.where is not None else ("", [])
File "C:\Users\BhathiyaTK\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\sql\compiler.py", line 415, in compile
sql, params = node.as_sql(self, self.connection)
File "C:\Users\BhathiyaTK\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\sql\where.py", line 81, in as_sql
sql, params = compiler.compile(child)
File "C:\Users\BhathiyaTK\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\sql\compiler.py", line 415, in compile
sql, params = node.as_sql(self, self.connection)
File "C:\Users\BhathiyaTK\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\lookups.py", line 177, in as_sql
rhs_sql, rhs_params = self.process_rhs(compiler, connection)
File "C:\Users\BhathiyaTK\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\lookups.py", line 270, in process_rhs
'The QuerySet value for an exact lookup must be limited to '
ValueError: The QuerySet value for an exact lookup must be limited to one result using slicing.
[30/Apr/2020 17:26:37] "GET /profile/ HTTP/1.1" 500 122259
Я новичок в Django и понятия не имею, почему он дает такую ошибку. Может кто-нибудь объяснить, почему это происходит и как решить эти проблемы? Я ценю вашу помощь. Я использую Python 3.7.4, Django 3.0.1