Я попробовал исправить здесь, но оно все равно не работает. объект ReverseManyToOneDescriptor не имеет атрибута order_by django 2.1
Что мне не хватает? ввод http://localhost: 8000 / themes / 1 / дает мне
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/topics/1/
Django Version: 3.0.6
Python Version: 3.7.2
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'learning_logs')
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 "E:\Personal projects\python\learning_log\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "E:\Personal projects\python\learning_log\venv\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "E:\Personal projects\python\learning_log\venv\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "E:\Personal projects\python\learning_log\learning_logs\views.py", line 20, in topic
entries = topic.entry_set.order_by('-date_added') # lowercase "t"
Exception Type: AttributeError at /topics/1/
Exception Value: 'Topic' object has no attribute 'entry_set'
Это мой views.py
from django.shortcuts import render
from .models import Topic
def index(request):
"""The home page for learning log"""
return render(request, 'learning_logs/index.html')
def topics(request):
"""Show all topics."""
topics = Topic.objects.order_by('date_added')
context = {'topics': topics}
return render(request, 'learning_logs/topics.html', context)
def topic(request, topic_id):
"""Show a single topic and all its entries"""
topic = Topic.objects.get(id=topic_id)
entries = topic.entry_set.order_by('-date_added') # lowercase "t"
context = {'topic': topic, 'entries': entries}
return render(request, 'learning_logs/topic.html', context)
В чем проблема? как я могу использовать entry_set?
Спасибо.