Ticket #2740: django-bug2740-patchfor-r7534.patch
File django-bug2740-patchfor-r7534.patch, 4.2 KB (added by , 17 years ago) |
---|
-
models/base.py
147 147 opts = cls._meta 148 148 opts._prepare(cls) 149 149 150 if opts.order_with_respect_to:151 cls.get_next_in_order = curry(cls._get_next_or_previous_in_order, is_next=True)152 cls.get_previous_in_order = curry(cls._get_next_or_previous_in_order, is_next=False)153 setattr(opts.order_with_respect_to.rel.to, 'get_%s_order' % cls.__name__.lower(), curry(method_get_order, cls))154 setattr(opts.order_with_respect_to.rel.to, 'set_%s_order' % cls.__name__.lower(), curry(method_set_order, cls))155 156 150 # Give the class a docstring -- its definition. 157 151 if cls.__doc__ is None: 158 152 cls.__doc__ = "%s(%s)" % (cls.__name__, ", ".join([f.attname for f in opts.fields])) … … 502 496 setattr(self, cachename, get_image_dimensions(filename)) 503 497 return getattr(self, cachename) 504 498 505 ############################################506 # HELPER FUNCTIONS (CURRIED MODEL METHODS) #507 ############################################508 509 # ORDERING METHODS #########################510 511 def method_set_order(ordered_obj, self, id_list):512 rel_val = getattr(self, ordered_obj._meta.order_with_respect_to.rel.field_name)513 order_name = ordered_obj._meta.order_with_respect_to.name514 # FIXME: It would be nice if there was an "update many" version of update515 # for situations like this.516 for i, j in enumerate(id_list):517 ordered_obj.objects.filter(**{'pk': j, order_name: rel_val}).update(_order=i)518 transaction.commit_unless_managed()519 520 def method_get_order(ordered_obj, self):521 rel_val = getattr(self, ordered_obj._meta.order_with_respect_to.rel.field_name)522 order_name = ordered_obj._meta.order_with_respect_to.name523 pk_name = ordered_obj._meta.pk.name524 return [r[pk_name] for r in525 ordered_obj.objects.filter(**{order_name: rel_val}).values(pk_name)]526 527 499 ############################################## 528 500 # HELPER FUNCTIONS (CURRIED MODEL FUNCTIONS) # 529 501 ############################################## -
models/fields/related.py
121 121 related = RelatedObject(other, cls, self) 122 122 self.contribute_to_related_class(other, related) 123 123 124 opts = other._meta 125 if opts.order_with_respect_to: 126 cls.get_next_in_order = curry(cls._get_next_or_previous_in_order, is_next=True) 127 cls.get_previous_in_order = curry(cls._get_next_or_previous_in_order, is_next=False) 128 setattr(opts.order_with_respect_to.rel.to, 'get_%s_order' % cls.__name__.lower(), curry(method_get_order, cls)) 129 setattr(opts.order_with_respect_to.rel.to, 'set_%s_order' % cls.__name__.lower(), curry(method_set_order, cls)) 130 131 124 132 def get_db_prep_lookup(self, lookup_type, value): 125 133 # If we are doing a lookup on a Related Field, we must be 126 134 # comparing object instances. The value should be the PK of value, … … 833 841 # so return None. 834 842 return None 835 843 844 845 ############################################ 846 # HELPER FUNCTIONS (CURRIED MODEL METHODS) # 847 ############################################ 848 849 # ORDERING METHODS ######################### 850 851 def method_set_order(ordered_obj, self, id_list): 852 rel_val = getattr(self, ordered_obj._meta.order_with_respect_to.rel.field_name) 853 order_name = ordered_obj._meta.order_with_respect_to.name 854 # FIXME: It would be nice if there was an "update many" version of update 855 # for situations like this. 856 for i, j in enumerate(id_list): 857 ordered_obj.objects.filter(**{'pk': j, order_name: rel_val}).update(_order=i) 858 transaction.commit_unless_managed() 859 860 def method_get_order(ordered_obj, self): 861 rel_val = getattr(self, ordered_obj._meta.order_with_respect_to.rel.field_name) 862 order_name = ordered_obj._meta.order_with_respect_to.name 863 pk_name = ordered_obj._meta.pk.name 864 return [r[pk_name] for r in 865 ordered_obj.objects.filter(**{order_name: rel_val}).values(pk_name)] 866