[英]Why do I get “TypeError: Meta defining class is not iterable” When using a readonly field in Django admin?
I defined my model as following: 我将模型定义如下:
from django.db import models
class Books(models.Model):
name = models.CharField(max_length=100)
author = models.CharField(max_length=100)
def __str__(self):
return str(self.name)
The problem is that when I want to make the author
field readonly
in admin.py
as following: 问题是,当我想在
admin.py
author
字段admin.py
readonly
时,如下所示:
from django.contrib import admin
from core.models import Books
class Books(admin.ModelAdmin):
readonly_fields=('author',)
admin.site.register(Books)
I get the following error upon running server: 运行服务器时出现以下错误:
Use a different name for model class and model admin class 为模型类和模型管理类使用不同的名称
class
BooksAdmin(admin.ModelAdmin): # change the model admin class name
readonly_fields = ('author',)
admin.site.register(
Books, BooksAdmin)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.