Fixed #81 -- Admin now supports primary_key=True for non-integer fields. 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
This commit is contained in:
parent
b3ae12fa4a
commit
199938649e
|
@ -50,9 +50,9 @@ urlpatterns += (
|
||||||
# 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)
|
||||||
|
|
|
@ -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.
|
||||||
|
@ -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.
|
||||||
|
|
|
@ -179,7 +179,7 @@ class Field(object):
|
||||||
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
|
||||||
|
|
|
@ -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),
|
||||||
|
|
|
@ -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 %%} <strong>{{ %s }}</strong>{%% endif %%}' % (obj_repr, obj_repr))
|
t.append('{%% if %s %%} <strong>{{ %s }}</strong>{%% endif %%}' % (obj_repr, obj_repr))
|
||||||
|
|
Loading…
Reference in New Issue