diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
index 6ab842d..d668e05 100644
a
|
b
|
from django.core.urlresolvers import reverse
|
21 | 21 | from django.db import models, transaction, router |
22 | 22 | from django.db.models.constants import LOOKUP_SEP |
23 | 23 | from django.db.models.related import RelatedObject |
24 | | from django.db.models.fields import BLANK_CHOICE_DASH, FieldDoesNotExist |
| 24 | from django.db.models.fields import (BLANK_CHOICE_DASH, FieldDoesNotExist, |
| 25 | AutoField) |
25 | 26 | from django.db.models.sql.constants import QUERY_TERMS |
26 | 27 | from django.forms.formsets import all_valid, DELETION_FIELD_NAME |
27 | 28 | from django.forms.models import (modelform_factory, modelformset_factory, |
… |
… |
class BaseModelAdmin(six.with_metaclass(RenameBaseModelAdminMethods)):
|
96 | 97 | radio_fields = {} |
97 | 98 | prepopulated_fields = {} |
98 | 99 | formfield_overrides = {} |
| 100 | auto_pk_readonly_field = True |
99 | 101 | readonly_fields = () |
100 | 102 | ordering = None |
101 | 103 | view_on_site = True |
… |
… |
class BaseModelAdmin(six.with_metaclass(RenameBaseModelAdminMethods)):
|
311 | 313 | """ |
312 | 314 | Hook for specifying custom readonly fields. |
313 | 315 | """ |
314 | | return self.readonly_fields |
| 316 | if (self.auto_pk_readonly_field and obj is not None |
| 317 | and not isinstance(self.opts.pk, AutoField)): |
| 318 | return self.readonly_fields + (self.opts.pk.attname,) |
| 319 | else: |
| 320 | return self.readonly_fields |
315 | 321 | |
316 | 322 | def get_prepopulated_fields(self, request, obj=None): |
317 | 323 | """ |
diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt
index 1301437..c23c794 100644
a
|
b
|
subclass::
|
159 | 159 | By default, the admin changelist will display it |
160 | 160 | (``actions_selection_counter = True``). |
161 | 161 | |
| 162 | .. attribute:: ModelAdmin.auto_pk_readonly_field |
| 163 | |
| 164 | .. versionadded:: 1.7 |
| 165 | |
| 166 | If the primary key is not an ``AutoField``, this controls whether the |
| 167 | primary key field is made read-only for existing objects. If set to |
| 168 | ``False``, the change form reverts to pre-1.7 behaviour and the primary |
| 169 | key field will remain editable. |
| 170 | |
162 | 171 | .. attribute:: ModelAdmin.date_hierarchy |
163 | 172 | |
164 | 173 | Set ``date_hierarchy`` to the name of a ``DateField`` or ``DateTimeField`` |
diff --git a/docs/releases/1.7.txt b/docs/releases/1.7.txt
index 2e596b3..2893f74 100644
a
|
b
|
Minor features
|
172 | 172 | <django.contrib.admin.ModelAdmin.view_on_site>` to control whether or not to |
173 | 173 | display the "View on site" link. |
174 | 174 | |
| 175 | * Primary key fields will now be read-only for change forms by default, but |
| 176 | can be made editable again by setting |
| 177 | :attr:`ModelAdmin.auto_pk_readonly_field<django.contrib.admin.ModelAdmin.auto_pk_readonly_field>` |
| 178 | to ``False``. |
| 179 | |
175 | 180 | :mod:`django.contrib.auth` |
176 | 181 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ |
177 | 182 | |