Open aaroneden opened 4 years ago
Hi !
try this in your view
from bson.objectid import ObjectId
backtest = BackTestResult.objects.get(_id=ObjectId(pk))
That did the trick @AlejandroOrostica Thank you so much! Is there a way a sample about this could be added to the Djongo site?
I don't know where to find documentation about djongo :(, i knew the solution because i have a similar issue with pymongo a few weeks ago,
I'm working with djongo right now and i'm stuck filtering lists and don't know where to read about that :((((
Cannot get objects based on the primary key. -
View HTML
View Python
Model Python
Traceback
Environment:
Request Method: GET Request URL: http://127.0.0.1:8000/backtests/5f0a7ca49de5c032d9773557/
Django Version: 3.0.5 Python Version: 3.7.3 Installed Applications: ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'backtests'] Installed Middleware: ['django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback (most recent call last): File "/Users/aaroneden/PycharmProjects/eStocks_Web/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner response = get_response(request) File "/Users/aaroneden/PycharmProjects/eStocks_Web/venv/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response response = self.process_exception_by_middleware(e, request) File "/Users/aaroneden/PycharmProjects/eStocks_Web/venv/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response response = wrapped_callback(request, *callback_args, *callback_kwargs) File "/Users/aaroneden/PycharmProjects/eStocks_Web/backtests/views.py", line 17, in backtest_detail backtest = BackTestResult.objects.get(pk=pk) File "/Users/aaroneden/PycharmProjects/eStocks_Web/venv/lib/python3.7/site-packages/django/db/models/manager.py", line 82, in manager_method return getattr(self.get_queryset(), name)(args, **kwargs) File "/Users/aaroneden/PycharmProjects/eStocks_Web/venv/lib/python3.7/site-packages/django/db/models/query.py", line 417, in get self.model._meta.object_name
Exception Type: DoesNotExist at /backtests/5f0a7ca49de5c032d9773557/ Exception Value: BackTestResult matching query does not exist.