Добрый вечер!
Учусь создавать сайт на Django. Решил немного кастомизировать админку. После того как я написал строку readonly_fields во вкладке admin.py и выполнил команду python manage.py runserver, у меня появилась ошибка:
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Program Files (x86)\Python\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\Program Files (x86)\Python\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "D:\django sites\testsite\venv\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "D:\django sites\testsite\venv\lib\site-packages\django\core\management\commands\runserver.py", line 11
8, in inner_run
self.check(display_num_errors=True)
File "D:\django sites\testsite\venv\lib\site-packages\django\core\management\base.py", line 442, in check
raise SystemCheckError(msg)
django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:
ERRORS:
<class 'news.admin.NewsAdmin'>: (admin.E035) The value of 'readonly_fields[1]' is not a callable, an attribute
of 'NewsAdmin', or an attribute of 'news.News'.
System check identified 1 issue (0 silenced).
admin.py
from django.contrib import admin
from django.utils.safestring import mark_safe
from .models import News, Category
class NewsAdmin(admin.ModelAdmin):
list_display = ('id', 'title', 'category', 'created_at', 'updated_at', 'is_published', 'get_photo')
list_display_links = ('id', 'title')
search_fields = ('title', 'content')
list_editable = ('is_published',)
list_filter = ('is_published', 'category')
fields = ('title', 'category', 'content', 'photo', 'get_photo', 'is_published', 'views', 'created_at', 'updated_at')
readonly_fields = ('get_photo', 'views', 'created_at', 'updated_at')
save_on_top = True
def get_photo(self, obj):
if obj.photo:
return mark_safe(f'<img src="{obj.photo.url}" width="75">')
else:
return '-'
get_photo.short_description = 'Миниатюра'
class CategoryAdmin(admin.ModelAdmin):
list_display = ('id', 'title')
list_display_links = ('id', 'title')
search_fields = ('title',)
admin.site.register(News, NewsAdmin)
admin.site.register(Category, CategoryAdmin)
admin.site.site_title = 'Управление новостями'
admin.site.site_header = 'Управление новостями'
Пожалуйста, помогите найти решение проблемы