TypeError at /admin/board/board/add/
getattr(): attribute name must be string
from django.contrib import admin
from .models import *
class BoardAdmin(admin.ModelAdmin):
list_display = ('id', 'title', 'release_year', 'published')
list_display_links = ('id', 'title', 'published')
search_fields = ('id', 'title', 'published')
admin.site.register(Board, BoardAdmin)
from django.db import models
class Board(models.Model):
title = models.CharField(verbose_name = 'Название фильма', max_length = 140)
content = models.TextField(verbose_name = 'Описание фильма')
release_year = models.IntegerField(verbose_name = 'Год выпуска фильма', db_index = True)
poster = models.ImageField(verbose_name = 'Постер фильма', height_field = 320, width_field = 220, upload_to = 'media/%Y/%m/%d/')
published = models.DateTimeField(verbose_name = 'Дата добавления фильма на сайт', auto_now_add = True, db_index = True)
def __str__(self):
return self.title
class Meta:
verbose_name = 'Информация о фильме'
verbose_name_plural = 'Фильмы'
ordering = ['-published']
from django.shortcuts import render
from .models import *
def index(request):
movie_list = Board.objects.all()
return render(request, 'board/index.html', {'movie_list' : movie_list})
<!DOCTYPE html>
<html>
<head>
<title>Фильмы - главная</title>
<meta charset="utf-8">
</head>
<body>
<h1>Список фильмов</h1>
<br>
{% for movie in movie_list %}
<div>
<p>{{ movie.title }}</p>
<p>{{ movie.content }}</p>
<p>{{ movie.release_year }}</p>
</div>
{% endfor %}
</body>
</html>