Использование базовой пользовательской модели Django.Я получаю дубликат ошибки, используя базовую модель ПК.Не уверен, почему мое приложение не может понять, какой пользователь публикует комментарий.
def view_api(request):
user = request.user
if request.method == 'POST':
if request.user.is_active:
price, created = Model.objects.get_or_create(
user=User.objects.filter(pk=user.pk),
anonymous_user=False,
comments=request.POST.get('comments')
)
Ошибка:
The QuerySet value for an exact lookup must be limited to one result using slicing.
Трассировка:
File "/Users/~/query.py" in get_or_create
538. return self.get(**kwargs), False
File "/Users/~/query.py" in get
402. num = len(clone)
File "/Users/~/query.py" in __len__
256. self._fetch_all()
File "/Users/~/query.py" in _fetch_all
1242. self._result_cache = list(self._iterable_class(self))
File "/Users/~/query.py" in __iter__
55. results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/Users/~/compiler.py" in execute_sql
1087. sql, params = self.as_sql()
File "/Users/~/compiler.py" in as_sql
489. where, w_params = self.compile(self.where) if self.where is not None else ("", [])
File "/Users/~/compiler.py" in compile
405. sql, params = node.as_sql(self, self.connection)
File "/Users/~/where.py" in as_sql
81. sql, params = compiler.compile(child)
File "/Users/~/compiler.py" in compile
405. sql, params = node.as_sql(self, self.connection)
File "/Users/~/related_lookups.py" in as_sql
130. return super().as_sql(compiler, connection)
File "/Users/~/lookups.py" in as_sql
163. rhs_sql, rhs_params = self.process_rhs(compiler, connection)
File "/Users/~/" in process_rhs
257. 'The QuerySet value for an exact lookup must be limited to '
Exception Type: ValueError at /api/voting/
Exception Value: The QuerySet value for an exact lookup must be limited to one result using slicing.