Ticket #2259: 2259-poc.diff

File 2259-poc.diff, 2.9 KB (added by bouke, 21 months ago)
  • django/contrib/admin/options.py

    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 
    2121from django.db import models, transaction, router
    2222from django.db.models.constants import LOOKUP_SEP
    2323from django.db.models.related import RelatedObject
    24 from django.db.models.fields import BLANK_CHOICE_DASH, FieldDoesNotExist
     24from django.db.models.fields import (BLANK_CHOICE_DASH, FieldDoesNotExist,
     25                                     AutoField)
    2526from django.db.models.sql.constants import QUERY_TERMS
    2627from django.forms.formsets import all_valid, DELETION_FIELD_NAME
    2728from django.forms.models import (modelform_factory, modelformset_factory,
    class BaseModelAdmin(six.with_metaclass(RenameBaseModelAdminMethods)): 
    9697    radio_fields = {}
    9798    prepopulated_fields = {}
    9899    formfield_overrides = {}
     100    auto_pk_readonly_field = True
    99101    readonly_fields = ()
    100102    ordering = None
    101103    view_on_site = True
    class BaseModelAdmin(six.with_metaclass(RenameBaseModelAdminMethods)): 
    311313        """
    312314        Hook for specifying custom readonly fields.
    313315        """
    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
    315321
    316322    def get_prepopulated_fields(self, request, obj=None):
    317323        """
  • docs/ref/contrib/admin/index.txt

    diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt
    index 1301437..c23c794 100644
    a b subclass:: 
    159159    By default, the admin changelist will display it
    160160    (``actions_selection_counter = True``).
    161161
     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
    162171.. attribute:: ModelAdmin.date_hierarchy
    163172
    164173    Set ``date_hierarchy`` to the name of a ``DateField`` or ``DateTimeField``
  • docs/releases/1.7.txt

    diff --git a/docs/releases/1.7.txt b/docs/releases/1.7.txt
    index 2e596b3..2893f74 100644
    a b Minor features 
    172172  <django.contrib.admin.ModelAdmin.view_on_site>` to control whether or not to
    173173  display the "View on site" link.
    174174
     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
    175180:mod:`django.contrib.auth`
    176181^^^^^^^^^^^^^^^^^^^^^^^^^^
    177182
Back to Top