Ticket #13574: django_m2m_field_name.diff
File django_m2m_field_name.diff, 3.4 KB (added by , 14 years ago) |
---|
-
django/db/models/sql/query.py
1240 1240 to_col2, opts, target) = cached_data 1241 1241 else: 1242 1242 table1 = field.m2m_db_table() 1243 from_col1 = opts.pk.column1243 from_col1 = field.m2m_to_field_name() 1244 1244 to_col1 = field.m2m_column_name() 1245 1245 opts = field.rel.to._meta 1246 1246 table2 = opts.db_table 1247 1247 from_col2 = field.m2m_reverse_name() 1248 to_col2 = opts.pk.column1248 to_col2 = field.m2m_reverse_to_field_name() 1249 1249 target = opts.pk 1250 1250 orig_opts._join_cache[name] = (table1, from_col1, 1251 1251 to_col1, table2, from_col2, to_col2, opts, … … 1293 1293 to_col2, opts, target) = cached_data 1294 1294 else: 1295 1295 table1 = field.m2m_db_table() 1296 from_col1 = opts.pk.column1296 from_col1 = field.m2m_reverse_to_field_name() 1297 1297 to_col1 = field.m2m_reverse_name() 1298 1298 opts = orig_field.opts 1299 1299 table2 = opts.db_table 1300 1300 from_col2 = field.m2m_column_name() 1301 to_col2 = opts.pk.column1301 to_col2 = field.m2m_to_field_name() 1302 1302 target = opts.pk 1303 1303 orig_opts._join_cache[name] = (table1, from_col1, 1304 1304 to_col1, table2, from_col2, to_col2, opts, -
django/db/models/fields/related.py
1020 1020 return getattr(self, cache_attr) 1021 1021 for f in self.rel.through._meta.fields: 1022 1022 if hasattr(f,'rel') and f.rel and f.rel.to == related.model: 1023 setattr(self, cache_attr, getattr(f, attr)) 1023 if attr == 'to_field': 1024 setattr(self, cache_attr, f.rel.field_name) 1025 else: 1026 setattr(self, cache_attr, getattr(f, attr)) 1024 1027 return getattr(self, cache_attr) 1025 1028 1026 1029 def _get_m2m_reverse_attr(self, related, attr): … … 1042 1045 else: 1043 1046 found = True 1044 1047 else: 1045 setattr(self, cache_attr, getattr(f, attr)) 1048 if attr == 'to_field': 1049 setattr(self, cache_attr, f.rel.field_name) 1050 else: 1051 setattr(self, cache_attr, getattr(f, attr)) 1046 1052 break 1047 1053 return getattr(self, cache_attr) 1048 1054 … … 1129 1135 self.m2m_field_name = curry(self._get_m2m_attr, related, 'name') 1130 1136 self.m2m_reverse_field_name = curry(self._get_m2m_reverse_attr, related, 'name') 1131 1137 1138 self.m2m_to_field_name = curry(self._get_m2m_attr, related, 'to_field') 1139 self.m2m_reverse_to_field_name = curry(self._get_m2m_reverse_attr, related, 'to_field') 1140 1132 1141 def set_attributes_from_rel(self): 1133 1142 pass 1134 1143