From 12c04fbf293f49f007176660a2b1fb4e279eedee Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Mon, 18 Jul 2005 20:35:51 +0000 Subject: [PATCH] Fixed bug in dynamically-generated docs -- ForeignKeys were throwing an exception git-svn-id: http://code.djangoproject.com/svn/django/trunk@182 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/views/admin/doc.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/django/views/admin/doc.py b/django/views/admin/doc.py index 7f8fa3b0b8..3b593e5944 100644 --- a/django/views/admin/doc.py +++ b/django/views/admin/doc.py @@ -275,6 +275,7 @@ DATA_TYPE_MAPPING = { 'EmailField' : 'E-mail address', 'FileField' : 'File path', 'FloatField' : 'Decimal number', + 'ForeignKey' : 'Integer', 'ImageField' : 'File path', 'IntegerField' : 'Integer', 'IPAddressField' : 'IP address', @@ -293,6 +294,9 @@ DATA_TYPE_MAPPING = { } def get_readable_field_data_type(field): + # ForeignKey is a special case. Use the field type of the relation. + if field.__class__.__name__ == 'ForeignKey': + field = field.rel.get_related_field() return DATA_TYPE_MAPPING[field.__class__.__name__] % field.__dict__ def extract_views_from_urlpatterns(urlpatterns, base=''): @@ -325,4 +329,4 @@ def simplify_regex(pattern): pattern = pattern.replace('^', '').replace('$', '').replace('?', '').replace('//', '/') if not pattern.startswith('/'): pattern = '/' + pattern - return pattern \ No newline at end of file + return pattern