Permalink
Browse files

Fixed #683 -- Lightly refactored meta.fields.Field to add an attname …

…attribute.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@1150 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent aae50fc commit 2ef937d0fdd607900f67ecc932309d87167ba89a @adrianholovaty adrianholovaty committed Nov 9, 2005
Showing with 94 additions and 77 deletions.
  1. +10 −10 django/contrib/admin/views/main.py
  2. +54 −54 django/core/meta/__init__.py
  3. +26 −9 django/core/meta/fields.py
  4. +2 −2 django/models/auth.py
  5. +2 −2 django/models/core.py
@@ -214,7 +214,7 @@ def change_list(request, app_label, module_name):
((lookup_val is None and ' class="selected"' or ''),
get_query_string(params, {}, [lookup_kwarg])))
for val in lookup_choices:
- pk_val = getattr(val, f.rel.to.pk.column)
+ pk_val = getattr(val, f.rel.to.pk.attname)
filter_template.append('<li%s><a href="%s">%r</a></li>\n' % \
((lookup_val == str(pk_val) and ' class="selected"' or ''),
get_query_string(params, {lookup_kwarg: pk_val}), val))
@@ -378,7 +378,7 @@ def change_list(request, app_label, module_name):
capfirst(f.verbose_name)))
raw_template.append('</tr>\n</thead>\n')
# Result rows.
- pk = lookup_opts.pk.name
+ pk = lookup_opts.pk.attname
for i, result in enumerate(result_list):
raw_template.append('<tr class="row%s">\n' % (i % 2 + 1))
for j, field_name in enumerate(lookup_opts.admin.list_display):
@@ -393,7 +393,7 @@ def change_list(request, app_label, module_name):
except ObjectDoesNotExist:
result_repr = EMPTY_CHANGELIST_VALUE
else:
- field_val = getattr(result, f.column)
+ field_val = getattr(result, f.attname)
# Foreign-key fields are special: Use the repr of the
# related object.
if isinstance(f.rel, meta.ManyToOne):
@@ -785,7 +785,7 @@ def add_stage(request, app_label, module_name, show_delete=False, form_url='', p
new_data.setlist(f.name, new_data[f.name].split(","))
manipulator.do_html2python(new_data)
new_object = manipulator.save(new_data)
- pk_value = getattr(new_object, opts.pk.column)
+ pk_value = getattr(new_object, opts.pk.attname)
log.log_action(request.user.id, opts.get_content_type_id(), pk_value, repr(new_object), log.ADDITION)
msg = 'The %s "%s" was added successfully.' % (opts.verbose_name, new_object)
# Here, we distinguish between different save types by checking for
@@ -887,7 +887,7 @@ def change_stage(request, app_label, module_name, object_id):
new_data.setlist(f.name, new_data[f.name].split(","))
manipulator.do_html2python(new_data)
new_object = manipulator.save(new_data)
- pk_value = getattr(new_object, opts.pk.column)
+ pk_value = getattr(new_object, opts.pk.attname)
# Construct the change message.
change_message = []
@@ -925,19 +925,19 @@ def change_stage(request, app_label, module_name, object_id):
new_data = {}
obj = manipulator.original_object
for f in opts.fields:
- new_data.update(_get_flattened_data(f, getattr(obj, f.column)))
+ new_data.update(_get_flattened_data(f, getattr(obj, f.attname)))
for f in opts.many_to_many:
get_list_func = getattr(obj, 'get_%s_list' % f.rel.singular)
if f.rel.raw_id_admin:
- new_data[f.name] = ",".join([str(getattr(i, f.rel.to.pk.column)) for i in get_list_func()])
+ new_data[f.name] = ",".join([str(getattr(i, f.rel.to.pk.attname)) for i in get_list_func()])
elif not f.rel.edit_inline:
- new_data[f.name] = [getattr(i, f.rel.to.pk.column) for i in get_list_func()]
+ new_data[f.name] = [getattr(i, f.rel.to.pk.attname) for i in get_list_func()]
for rel_obj, rel_field in inline_related_objects:
var_name = rel_obj.object_name.lower()
for i, rel_instance in enumerate(getattr(obj, 'get_%s_list' % opts.get_rel_object_method_name(rel_obj, rel_field))()):
for f in rel_obj.fields:
if f.editable and f != rel_field:
- for k, v in _get_flattened_data(f, getattr(rel_instance, f.column)).items():
+ for k, v in _get_flattened_data(f, getattr(rel_instance, f.attname)).items():
new_data['%s.%d.%s' % (var_name, i, k)] = v
for f in rel_obj.many_to_many:
new_data['%s.%d.%s' % (var_name, i, f.column)] = [j.id for j in getattr(rel_instance, 'get_%s_list' % f.rel.singular)()]
@@ -1026,7 +1026,7 @@ def _get_deleted_objects(deleted_objects, perms_needed, user, obj, opts, current
# Display a link to the admin page.
nh(deleted_objects, current_depth, ['%s: <a href="../../../../%s/%s/%s/">%r</a>' % \
(capfirst(rel_opts.verbose_name), rel_opts.app_label, rel_opts.module_name,
- getattr(sub_obj, rel_opts.pk.column), sub_obj), []])
+ getattr(sub_obj, rel_opts.pk.attname), sub_obj), []])
_get_deleted_objects(deleted_objects, perms_needed, user, sub_obj, rel_opts, current_depth+2)
else:
has_related_objs = False
Oops, something went wrong.

0 comments on commit 2ef937d

Please sign in to comment.