Q:

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:
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:

A:

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)

