Opened 6 years ago

Closed 6 years ago

#6402 closed (duplicate)

order_with_respect_to = 'some_field' fails if some_field = ForeignKey('self', ...)

Reported by: anonymous Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: UI/UX:


A trivial change will fix this (add the method with setattr() to self if required):

--- django/db/models/      (revision 7018)
+++ django/db/models/      (working copy)
@@ -194,8 +195,16 @@
         if opts.order_with_respect_to:
             cls.get_next_in_order = curry(cls._get_next_or_previous_in_order, is_next=True)
             cls.get_previous_in_order = curry(cls._get_next_or_previous_in_order, is_next=False)
-            setattr(, 'get_%s_order' % cls.__name__.lower(), curry(method_get_order, cls))
-            setattr(, 'set_%s_order' % cls.__name__.lower(), curry(method_set_order, cls))
+            if type( in types.StringTypes \
+                    and == \
+                        cls._meta.object_name:
+                target = cls
+            else:
+                target =
+            setattr(target, 'get_%s_order' % cls.__name__.lower(),
+                    curry(method_get_order, cls))
+            setattr(target, 'set_%s_order' % cls.__name__.lower(),
+                    curry(method_set_order, cls))
         # Give the class a docstring -- its definition.
         if cls.__doc__ is None:

Attachments (0)

Change History (3)

comment:1 Changed 6 years ago by anonymous

  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement unset

comment:2 Changed 6 years ago by anonymous

Looks like a duplicate of #2740. Leaving open for the fix provided.

comment:3 Changed 6 years ago by jacob

  • Resolution set to duplicate
  • Status changed from new to closed

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.