diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2005-08-10 19:32:38 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2005-08-10 19:32:38 +0000 |
| commit | 199938649e36389750eef6f097bae46977e796f5 (patch) | |
| tree | 8c52443a29b7e90449a8ac2e369f26c202be0a77 | |
| parent | b3ae12fa4ac3192b732be76f26ff707b60639bd1 (diff) | |
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
| -rw-r--r-- | django/conf/urls/admin.py | 6 | ||||
| -rw-r--r-- | django/core/meta/__init__.py | 4 | ||||
| -rw-r--r-- | django/core/meta/fields.py | 2 | ||||
| -rw-r--r-- | django/models/auth.py | 2 | ||||
| -rw-r--r-- | django/views/admin/main.py | 2 |
5 files changed, 9 insertions, 7 deletions
diff --git a/django/conf/urls/admin.py b/django/conf/urls/admin.py index dbe30940d6..841d50523e 100644 --- a/django/conf/urls/admin.py +++ b/django/conf/urls/admin.py @@ -50,9 +50,9 @@ urlpatterns += ( # 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) diff --git a/django/core/meta/__init__.py b/django/core/meta/__init__.py index 99abbd728c..554ba4eda0 100644 --- a/django/core/meta/__init__.py +++ b/django/core/meta/__init__.py @@ -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. diff --git a/django/core/meta/fields.py b/django/core/meta/fields.py index 46e317dca4..adbfe4ca92 100644 --- a/django/core/meta/fields.py +++ b/django/core/meta/fields.py @@ -179,7 +179,7 @@ class Field(object): 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 diff --git a/django/models/auth.py b/django/models/auth.py index 0b6d01069e..91ed0650ec 100644 --- a/django/models/auth.py +++ b/django/models/auth.py @@ -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), diff --git a/django/views/admin/main.py b/django/views/admin/main.py index 210523a8bb..430ae15744 100644 --- a/django/views/admin/main.py +++ b/django/views/admin/main.py @@ -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 %%} <strong>{{ %s }}</strong>{%% endif %%}' % (obj_repr, obj_repr)) |
