Ticket #18098: order_wrt.diff

File order_wrt.diff, 1.2 KB (added by Daniel Swarbrick, 13 years ago)
  • django/db/models/base.py

     
    233233            # defer creating accessors on the foreign class until we are
    234234            # certain it has been created
    235235            def make_foreign_order_accessors(field, model, cls):
     236                # Derive method name from related_name if defined (and if not
     237                # a self-join).
     238                if field.rel.to != cls and field.rel.related_name:
     239                    related_name = field.rel.related_name
     240                else:
     241                    related_name = cls.__name__.lower()
    236242                setattr(
    237243                    field.rel.to,
    238                     'get_%s_order' % cls.__name__.lower(),
     244                    'get_%s_order' % related_name,
    239245                    curry(method_get_order, cls)
    240246                )
    241247                setattr(
    242248                    field.rel.to,
    243                     'set_%s_order' % cls.__name__.lower(),
     249                    'set_%s_order' % related_name,
    244250                    curry(method_set_order, cls)
    245251                )
    246252            add_lazy_relation(
Back to Top