Skip to content

Commit

Permalink
Fixed #81 -- Admin now supports primary_key=True for non-integer fiel…
Browse files Browse the repository at this point in the history
…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
adrianholovaty committed Aug 10, 2005
1 parent b3ae12f commit 1999386
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions django/conf/urls/admin.py
Expand Up @@ -50,9 +50,9 @@
# Metasystem admin pages # Metasystem admin pages
('^(?P<app_label>[^/]+)/(?P<module_name>[^/]+)/$', 'django.views.admin.main.change_list'), ('^(?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>[^/]+)/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>[^/]+)/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) urlpatterns = patterns('', *urlpatterns)
4 changes: 2 additions & 2 deletions django/core/meta/__init__.py
Expand Up @@ -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." assert obj_key is not None, "ChangeManipulator.__init__() must be passed obj_key parameter."
self.obj_key = obj_key self.obj_key = obj_key
try: 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: except ObjectDoesNotExist:
# If the object doesn't exist, this might be a manipulator for a # 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. # one-to-one related object that hasn't created its subobject yet.
Expand All @@ -1358,7 +1358,7 @@ def manipulator_init(opts, add, change, self, obj_key=None):
raise raise
self.fields = [] self.fields = []
for f in opts.fields + opts.many_to_many: 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)) self.fields.extend(f.get_manipulator_fields(opts, self, change))


# Add fields for related objects. # Add fields for related objects.
Expand Down
2 changes: 1 addition & 1 deletion django/core/meta/fields.py
Expand Up @@ -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))) params['validator_list'].append(getattr(manipulator, 'isUnique%sFor%s' % (self.name, self.unique_for_month)))
if self.unique_for_year: if self.unique_for_year:
params['validator_list'].append(getattr(manipulator, 'isUnique%sFor%s' % (self.name, 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)) params['validator_list'].append(curry(manipulator_validator_unique, self, opts, manipulator))


# Only add is_required=True if the field cannot be blank. Primary keys # Only add is_required=True if the field cannot be blank. Primary keys
Expand Down
2 changes: 1 addition & 1 deletion django/models/auth.py
Expand Up @@ -247,7 +247,7 @@ class LogEntry(meta.Model):
meta.DateTimeField('action_time', auto_now=True), meta.DateTimeField('action_time', auto_now=True),
meta.ForeignKey(User), meta.ForeignKey(User),
meta.ForeignKey(core.ContentType, name='content_type_id', rel_name='content_type', blank=True, null=True), 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.CharField('object_repr', maxlength=200),
meta.PositiveSmallIntegerField('action_flag'), meta.PositiveSmallIntegerField('action_flag'),
meta.TextField('change_message', blank=True), meta.TextField('change_message', blank=True),
Expand Down
2 changes: 2 additions & 0 deletions django/views/admin/main.py
Expand Up @@ -719,6 +719,8 @@ def _get_admin_field(field_list, name_prefix, rel, add, change):
class_names.append('inline') 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('<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)) 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): if change and use_raw_id_admin(field):
obj_repr = '%soriginal.get_%s|truncatewords:"14"' % (rel and name_prefix or '', field.rel.name) 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)) t.append('{%% if %s %%}&nbsp;<strong>{{ %s }}</strong>{%% endif %%}' % (obj_repr, obj_repr))
Expand Down

0 comments on commit 1999386

Please sign in to comment.