mirror of https://github.com/django/django.git
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
This commit is contained in:
parent
9b98383175
commit
1d2ab36068
|
@ -522,7 +522,7 @@ class ModelBase(type):
|
||||||
# RECURSIVE_RELATIONSHIP_CONSTANT, create that relationship formally.
|
# RECURSIVE_RELATIONSHIP_CONSTANT, create that relationship formally.
|
||||||
if f.rel and f.rel.to == RECURSIVE_RELATIONSHIP_CONSTANT:
|
if f.rel and f.rel.to == RECURSIVE_RELATIONSHIP_CONSTANT:
|
||||||
f.rel.to = opts
|
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.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
|
f.rel.field_name = f.rel.field_name or f.rel.to.pk.name
|
||||||
# Add "get_thingie" methods for many-to-one related objects.
|
# Add "get_thingie" methods for many-to-one related objects.
|
||||||
|
@ -2046,7 +2046,7 @@ class ForeignKey(Field):
|
||||||
to_name = to._meta.object_name.lower()
|
to_name = to._meta.object_name.lower()
|
||||||
except AttributeError: # to._meta doesn't exist, so it must be RECURSIVE_RELATIONSHIP_CONSTANT
|
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)
|
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', '')
|
kwargs['verbose_name'] = kwargs.get('verbose_name', '')
|
||||||
else:
|
else:
|
||||||
to_field = to_field or to._meta.pk.name
|
to_field = to_field or to._meta.pk.name
|
||||||
|
|
Loading…
Reference in New Issue