Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed bug for models with a ForeignKey('self') and order_with_respect_to

git-svn-id: http://code.djangoproject.com/svn/django/trunk@332 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 1d2ab3606848fb062554a53f33b24d8ce9adbd75 1 parent 9b98383
@adrianholovaty adrianholovaty authored
Showing with 2 additions and 2 deletions.
  1. +2 −2 django/core/meta.py
View
4 django/core/meta.py
@@ -522,7 +522,7 @@ def __new__(cls, name, bases, attrs):
# RECURSIVE_RELATIONSHIP_CONSTANT, create that relationship formally.
if f.rel and f.rel.to == RECURSIVE_RELATIONSHIP_CONSTANT:
f.rel.to = opts
- f.name = (f.rel.name or f.rel.to.object_name.lower()) + '_' + f.rel.to.pk.name
+ f.name = f.name or ((f.rel.name or f.rel.to.object_name.lower()) + '_' + f.rel.to.pk.name)
f.verbose_name = f.verbose_name or f.rel.to.verbose_name
f.rel.field_name = f.rel.field_name or f.rel.to.pk.name
# Add "get_thingie" methods for many-to-one related objects.
@@ -2046,7 +2046,7 @@ def __init__(self, to, to_field=None, rel_name=None, **kwargs):
to_name = to._meta.object_name.lower()
except AttributeError: # to._meta doesn't exist, so it must be RECURSIVE_RELATIONSHIP_CONSTANT
assert to == 'self', "ForeignKey(%r) is invalid. First parameter to ForeignKey must be either a model or the string %r" % (to, RECURSIVE_RELATIONSHIP_CONSTANT)
- kwargs['name'] = ''
+ kwargs['name'] = kwargs.get('name', '')
kwargs['verbose_name'] = kwargs.get('verbose_name', '')
else:
to_field = to_field or to._meta.pk.name
Please sign in to comment.
Something went wrong with that request. Please try again.