Невозможно обновить пост с помощью моделей в django

Я хочу подготовить веб-страницу, которая выводит название книги, издательство и автора, и хочу добавить данные динамически с помощью панели администратора, но не могу сделать это, используя приведенный ниже код. Пожалуйста, помогите

models.py

from django.db import models
class researchpaper(models.Model):
    title = models.CharField(max_length=200)
    publication = models.CharField(max_length=200)
    authors = models.CharField(max_length=200)

    def __str__(self) -> str:
        return self.title

views.py

def publications(request):
    context = {
            'researchposts': researchpaper.objects.all()
    }
    return render(request, 'lab/publications.html',context)

urls.py

path('publications', views.publications, name='publications'),

html файл

 {% for paper in object_list %}
                <tr>
                    <td>
                        <h5>2021</h5>
                        <p style="color: black;"><b>{{paper.title}}1. A minimal model for synaptic integration in simple neurons</b></p>
                        <p style="font-size: 14px;"><i>Physica D: Nonlinear Phenomena, 2021</i></p>
                        <p style="font-size: 14px;"><i>Adrian Alva, Harjinder Singh.</i></p>
                    </td>
                    <td><a href="#"
                            target="blank" style="color: dodgerblue;"><i class="ai ai-google-scholar-square ai-2x"
                                style="padding-right: 10px;"></i></a></td>
                </tr>
                <tr>
                    <td>
                        <hr>
                    </td>
                </tr>
                {% endfor %}

Должен ли object_list в вашем шаблоне быть researchposts, поскольку именно этот ключ вы предоставляете в контексте?

{% for paper in researchposts %}
...

Измените ваш views.py следующим образом:

def publications(request):
    researchposts = researchpaper.objects.values('title', 'publications', 'author')
    return render(request, 'lab/publications.html', {'researchposts':researchposts})

В вашем html-файле (lab/publications.html):

{% for text in researchposts %}
Name: {{ text.title }} <br>
Pub: {{ text.publications }} <br>
Author: {{ text.author }} <br>
{% endfor %}
Вернуться на верх