Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #81 -- Admin now supports primary_key=True for non-integer fiel…

…ds. Note that you'll have to make a change to your database if you're using a previous Django installation and want to use non-integer primary key fields. See the BackwardsIncompatibleChanges wiki page for info.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@469 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 199938649e36389750eef6f097bae46977e796f5 1 parent b3ae12f
Adrian Holovaty adrianholovaty authored
6 django/conf/urls/admin.py
View
@@ -50,9 +50,9 @@
# Metasystem admin pages
('^(?P<app_label>[^/]+)/(?P<module_name>[^/]+)/$', 'django.views.admin.main.change_list'),
('^(?P<app_label>[^/]+)/(?P<module_name>[^/]+)/add/$', 'django.views.admin.main.add_stage'),
- ('^(?P<app_label>[^/]+)/(?P<module_name>[^/]+)/(?P<object_id>\d+)/$', 'django.views.admin.main.change_stage'),
- ('^(?P<app_label>[^/]+)/(?P<module_name>[^/]+)/(?P<object_id>\d+)/delete/$', 'django.views.admin.main.delete_stage'),
- ('^(?P<app_label>[^/]+)/(?P<module_name>[^/]+)/(?P<object_id>\d+)/history/$', 'django.views.admin.main.history'),
('^(?P<app_label>[^/]+)/(?P<module_name>[^/]+)/jsvalidation/$', 'django.views.admin.jsvalidation.jsvalidation'),
+ ('^(?P<app_label>[^/]+)/(?P<module_name>[^/]+)/(?P<object_id>.+)/history/$', 'django.views.admin.main.history'),
+ ('^(?P<app_label>[^/]+)/(?P<module_name>[^/]+)/(?P<object_id>.+)/delete/$', 'django.views.admin.main.delete_stage'),
+ ('^(?P<app_label>[^/]+)/(?P<module_name>[^/]+)/(?P<object_id>.+)/$', 'django.views.admin.main.change_stage'),
)
urlpatterns = patterns('', *urlpatterns)
4 django/core/meta/__init__.py
View
@@ -1338,7 +1338,7 @@ def manipulator_init(opts, add, change, self, obj_key=None):
assert obj_key is not None, "ChangeManipulator.__init__() must be passed obj_key parameter."
self.obj_key = obj_key
try:
- self.original_object = opts.get_model_module().get_object(**{'%s__exact' % opts.pk.name: obj_key})
+ self.original_object = opts.get_model_module().get_object(pk=obj_key)
except ObjectDoesNotExist:
# If the object doesn't exist, this might be a manipulator for a
# one-to-one related object that hasn't created its subobject yet.
@@ -1358,7 +1358,7 @@ def manipulator_init(opts, add, change, self, obj_key=None):
raise
self.fields = []
for f in opts.fields + opts.many_to_many:
- if f.editable and (not f.rel or not f.rel.edit_inline):
+ if f.editable and not (f.primary_key and change) and (not f.rel or not f.rel.edit_inline):
self.fields.extend(f.get_manipulator_fields(opts, self, change))
# Add fields for related objects.
2  django/core/meta/fields.py
View
@@ -179,7 +179,7 @@ def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=
params['validator_list'].append(getattr(manipulator, 'isUnique%sFor%s' % (self.name, self.unique_for_month)))
if self.unique_for_year:
params['validator_list'].append(getattr(manipulator, 'isUnique%sFor%s' % (self.name, self.unique_for_year)))
- if self.unique:
+ if self.unique or (self.primary_key and not rel):
params['validator_list'].append(curry(manipulator_validator_unique, self, opts, manipulator))
# Only add is_required=True if the field cannot be blank. Primary keys
2  django/models/auth.py
View
@@ -247,7 +247,7 @@ class LogEntry(meta.Model):
meta.DateTimeField('action_time', auto_now=True),
meta.ForeignKey(User),
meta.ForeignKey(core.ContentType, name='content_type_id', rel_name='content_type', blank=True, null=True),
- meta.IntegerField('object_id', blank=True, null=True),
+ meta.TextField('object_id', blank=True, null=True),
meta.CharField('object_repr', maxlength=200),
meta.PositiveSmallIntegerField('action_flag'),
meta.TextField('change_message', blank=True),
2  django/views/admin/main.py
View
@@ -719,6 +719,8 @@ def _get_admin_field(field_list, name_prefix, rel, add, change):
class_names.append('inline')
t.append('<label for="%s"%s>%s:</label> ' % (label_name, class_names and ' class="%s"' % ' '.join(class_names) or '', capfirst(field.verbose_name)))
t.append(_get_admin_field_form_widget(field, name_prefix, rel, add, change))
+ if change and field.primary_key:
+ t.append('{{ %soriginal.%s }}' % ((rel and name_prefix or ''), field.name))
if change and use_raw_id_admin(field):
obj_repr = '%soriginal.get_%s|truncatewords:"14"' % (rel and name_prefix or '', field.rel.name)
t.append('{%% if %s %%}&nbsp;<strong>{{ %s }}</strong>{%% endif %%}' % (obj_repr, obj_repr))
Please sign in to comment.
Something went wrong with that request. Please try again.