安装依赖关系
pip install django-readonly-field
在settings.py 中加入:
INSTALLED_APPS = [ # ... "django_readonly_field", ]
在你的model中加入
class Spaceship(models.Model): name = models.CharField(max_length=100) color = models.CharField(max_length=16) class ReadonlyMeta: readonly = ["color"]