Browse files

First pass at read-only pk's by default.

See ticket #2259
  • Loading branch information...
1 parent d9330d5 commit a9c039e9ed346808c66cb83664011225f3d2fdfe @streeter committed Mar 5, 2013
Showing with 7 additions and 0 deletions.
  1. +7 −0 django/contrib/admin/options.py
View
7 django/contrib/admin/options.py
@@ -348,6 +348,7 @@ class ModelAdmin(BaseModelAdmin):
save_on_top = False
paginator = Paginator
inlines = []
+ readonly_fields = ('pk',)
# Custom templates (designed to be over-ridden in subclasses)
add_form_template = None
@@ -370,6 +371,12 @@ def __init__(self, model, admin_site):
self.admin_site = admin_site
super(ModelAdmin, self).__init__()
+ # Translate pk to the name of the attribute
+ if 'pk' in self.readonly_fields:
+ self.readonly_fields = (tuple([f for f in self.readonly_fields
+ if f is not 'pk'])
+ + (self.opts.pk.attname, ))
+
def get_inline_instances(self, request, obj=None):
inline_instances = []
for inline_class in self.inlines:

0 comments on commit a9c039e

Please sign in to comment.