Permalink
Browse files

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
  • Loading branch information...
1 parent cf4c164 commit 12c04fbf293f49f007176660a2b1fb4e279eedee @adrianholovaty adrianholovaty committed Jul 18, 2005
Showing with 5 additions and 1 deletion.
  1. +5 −1 django/views/admin/doc.py
View
6 django/views/admin/doc.py
@@ -275,6 +275,7 @@ def get_return_data_type(func_name):
'EmailField' : 'E-mail address',
'FileField' : 'File path',
'FloatField' : 'Decimal number',
+ 'ForeignKey' : 'Integer',
'ImageField' : 'File path',
'IntegerField' : 'Integer',
'IPAddressField' : 'IP address',
@@ -293,6 +294,9 @@ def get_return_data_type(func_name):
}
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
+ return pattern

0 comments on commit 12c04fb

Please sign in to comment.