N
N
neponimaushii2021-03-31 21:02:25
Django
neponimaushii, 2021-03-31 21:02:25

Django. How to open detailed information for news/products?

Hi everyone, help needed! I am developing a site, it has a model that posts news on the main page through the admin panel. Here is her code:
models.py:

Class Task(models.Model):
    title = models.CharField('Название', max_length=50, help_text='Введите название')
    text = models.TextField('Описание')
    text1 = models.TextField('Подробное Описание', null=True,)
    img = models.ImageField("Изображение", upload_to="media/", null=True, )
    time = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.title

views.py:
def index(request):
    news = Task.objects.order_by('-id')
    return render(request, 'main/index.html', {'tasks': news})

News on the page are displayed normally, everything works. Here is the Html template of the main page itself:
{ % block content %}

    {% for el in tasks %}

        <div class="news imgb">
            <nav>
                <a href="{% url 'news' %}">

                <h3>
                {{ el.title }}
                </h3>
И так далее, там вывод фотки, описания и времени.

But when I want to open detailed information, I get an error: Task_list is missing a QuerySet. Define Task_list.model, Task_list.queryset, or override Task_list.get_queryset().

Here is the urls.py code:
urlpatterns = [
    path('', views.index, name='home'),
    path('about', views.about, name='about'),
    path('learners', views.learn, name='learn'),
    path('galery', views.galery, name='galery'),
    url('news/$', views.Task_list.as_view(), name='news'),
]

And the views.py code for news:
class Task_list(generic.ListView):
    news_one = Task

It may be that I call this page in the wrong way, or I wrote the code wrong. But I have already tried everything, the news itself is perfectly stamped, but none of them opens sub-junior information. Maybe it's in the news template, how to display information on it correctly?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexeytur, 2021-04-02
@Alexeytur

according to https://docs.djangoproject.com/en/3.1/ref/class-ba...

class Task_list(generic.ListView):
    model = Task

M
maksam07, 2021-04-11
@maksam07

I once noted one very important thing for myself:
60733e035dde1827934492.png
this is off topic, but should be useful

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question