Ticket #683: meta__init__.patch
File meta__init__.patch, 26.9 KB (added by , 19 years ago) |
---|
-
django/core/meta/__init__.py
153 153 exceptions=None, permissions=None, get_latest_by=None, 154 154 order_with_respect_to=None, module_constants=None): 155 155 156 #jgd 157 #print "initing Options for " + verbose_name 158 156 159 # Save the original function args, for use by copy(). Note that we're 157 160 # NOT using copy.deepcopy(), because that would create a new copy of 158 161 # everything in memory, and it's better to conserve memory. Of course, … … 209 212 if f.primary_key: 210 213 self.pk = f 211 214 break 215 #jgd 216 #if self.pk: 217 # print "found pk " + self.pk.name 218 # if self.pk.db_column: 219 # print "col " + self.pk.db_column 220 #else: 221 # print "didn't find pk" 212 222 # If a primary_key field hasn't been specified, add an 213 223 # auto-incrementing primary-key ID field automatically. 214 224 if self.pk is None: … … 408 418 # Gather all attributes that are Field instances. 409 419 fields = [] 410 420 for obj_name, obj in attrs.items(): 421 print "field: " + obj_name 411 422 if isinstance(obj, Field): 412 423 obj.set_name(obj_name) 413 424 fields.append(obj) … … 760 771 val = getattr(rel_obj, f.rel.field_name) 761 772 except AttributeError: 762 773 raise TypeError, "Invalid value: %r should be a %s instance, not a %s" % (f.name, f.rel.to, type(rel_obj)) 763 setattr(self, f.column, val) 774 #jgd 775 #setattr(self, f.column, val) 776 setattr(self, f.name, val) 764 777 else: 765 778 val = kwargs.pop(f.name, f.get_default()) 766 779 setattr(self, f.name, val) 767 780 if kwargs: 768 781 raise TypeError, "'%s' is an invalid keyword argument for this function" % kwargs.keys()[0] 769 782 for i, arg in enumerate(args): 770 setattr(self, opts.fields[i].column, arg) 783 #jgd 784 #setattr(self, opts.fields[i].column, arg) 785 setattr(self, opts.fields[i].name, arg) 771 786 772 787 def method_eq(opts, self, other): 773 return isinstance(other, self.__class__) and getattr(self, opts.pk.column) == getattr(other, opts.pk.column) 788 #jgd 789 #return isinstance(other, self.__class__) and getattr(self, opts.pk.column) == getattr(other, opts.pk.column) 790 return isinstance(other, self.__class__) and getattr(self, opts.pk.name) == getattr(other, opts.pk.name) 774 791 775 792 def method_save(opts, self): 776 793 # Run any pre-save hooks. … … 779 796 non_pks = [f for f in opts.fields if not f.primary_key] 780 797 cursor = db.db.cursor() 781 798 799 #jgd 800 #print "saving" 782 801 # First, try an UPDATE. If that doesn't update anything, do an INSERT. 783 pk_val = getattr(self, opts.pk.column) 802 #jgd 803 #pk_val = getattr(self, opts.pk.column) 804 pk_val = getattr(self, opts.pk.name) 784 805 pk_set = bool(pk_val) 785 806 record_exists = True 786 807 if pk_set: 808 #jgd 809 #print "pk set" 787 810 # Determine whether a record with the primary key already exists. 788 811 cursor.execute("SELECT 1 FROM %s WHERE %s=%%s LIMIT 1" % (opts.db_table, opts.pk.column), [pk_val]) 789 812 # If it does already exist, do an UPDATE. 790 813 if cursor.fetchone(): 791 db_values = [f.get_db_prep_save(f.pre_save(getattr(self, f.column), False)) for f in non_pks] 814 #jgd 815 #db_values = [f.get_db_prep_save(f.pre_save(getattr(self, f.column), False)) for f in non_pks] 816 db_values = [f.get_db_prep_save(f.pre_save(getattr(self, f.name), False)) for f in non_pks] 792 817 cursor.execute("UPDATE %s SET %s WHERE %s=%%s" % (opts.db_table, 793 818 ','.join(['%s=%%s' % f.column for f in non_pks]), opts.pk.column), 794 819 db_values + [pk_val]) 795 820 else: 796 821 record_exists = False 797 822 if not pk_set or not record_exists: 823 #jgd 824 #print "pk not set" 825 #jgd 798 826 field_names = [f.column for f in opts.fields if not isinstance(f, AutoField)] 827 #>field_names = [f.name for f in opts.fields if not isinstance(f, AutoField)] 799 828 placeholders = ['%s'] * len(field_names) 800 db_values = [f.get_db_prep_save(f.pre_save(getattr(self, f.column), True)) for f in opts.fields if not isinstance(f, AutoField)] 829 #jgd 830 #<db_values = [f.get_db_prep_save(f.pre_save(getattr(self, f.column), True)) for f in opts.fields if not isinstance(f, AutoField)] 831 db_values = [f.get_db_prep_save(f.pre_save(getattr(self, f.name), True)) for f in opts.fields if not isinstance(f, AutoField)] 801 832 if opts.order_with_respect_to: 802 833 field_names.append('_order') 803 834 # TODO: This assumes the database supports subqueries. 804 835 placeholders.append('(SELECT COUNT(*) FROM %s WHERE %s = %%s)' % \ 805 836 (opts.db_table, opts.order_with_respect_to.column)) 806 db_values.append(getattr(self, opts.order_with_respect_to.column)) 837 #jgd 838 #db_values.append(getattr(self, opts.order_with_respect_to.column)) 839 db_values.append(getattr(self, opts.order_with_respect_to.name)) 807 840 cursor.execute("INSERT INTO %s (%s) VALUES (%s)" % (opts.db_table, 808 841 ','.join(field_names), ','.join(placeholders)), db_values) 809 842 if opts.has_auto_field: 810 setattr(self, opts.pk.column, db.get_last_insert_id(cursor, opts.db_table, opts.pk.column)) 843 #jgd 844 #setattr(self, opts.pk.column, db.get_last_insert_id(cursor, opts.db_table, opts.pk.column)) 845 setattr(self, opts.pk.name, db.get_last_insert_id(cursor, opts.db_table, opts.pk.column)) 811 846 db.db.commit() 812 847 # Run any post-save hooks. 813 848 if hasattr(self, '_post_save'): 814 849 self._post_save() 815 850 816 851 def method_delete(opts, self): 817 assert getattr(self, opts.pk.column) is not None, "%r can't be deleted because it doesn't have an ID." 852 #jgd 853 #assert getattr(self, opts.pk.column) is not None, "%r can't be deleted because it doesn't have an ID." 854 assert getattr(self, opts.pk.name) is not None, "%r can't be deleted because it doesn't have an ID." 818 855 # Run any pre-delete hooks. 819 856 if hasattr(self, '_pre_delete'): 820 857 self._pre_delete() … … 832 869 for sub_obj in getattr(self, 'get_%s_list' % rel_opts_name)(): 833 870 sub_obj.delete() 834 871 for rel_opts, rel_field in opts.get_all_related_many_to_many_objects(): 872 #jgd 873 #cursor.execute("DELETE FROM %s WHERE %s_id=%%s" % (rel_field.get_m2m_db_table(rel_opts), 874 # self._meta.object_name.lower()), [getattr(self, opts.pk.column)]) 835 875 cursor.execute("DELETE FROM %s WHERE %s_id=%%s" % (rel_field.get_m2m_db_table(rel_opts), 836 self._meta.object_name.lower()), [getattr(self, opts.pk.column)]) 876 self._meta.object_name.lower()), [getattr(self, opts.pk.name)]) 877 837 878 for f in opts.many_to_many: 879 #jgd 880 #cursor.execute("DELETE FROM %s WHERE %s_id=%%s" % (f.get_m2m_db_table(opts), self._meta.object_name.lower()), 881 # [getattr(self, opts.pk.column)]) 838 882 cursor.execute("DELETE FROM %s WHERE %s_id=%%s" % (f.get_m2m_db_table(opts), self._meta.object_name.lower()), 839 [getattr(self, opts.pk.column)]) 840 cursor.execute("DELETE FROM %s WHERE %s=%%s" % (opts.db_table, opts.pk.column), [getattr(self, opts.pk.column)]) 883 [getattr(self, opts.pk.name)]) 884 885 #jgd 886 #cursor.execute("DELETE FROM %s WHERE %s=%%s" % (opts.db_table, opts.pk.column), [getattr(self, opts.pk.column)]) 887 cursor.execute("DELETE FROM %s WHERE %s=%%s" % (opts.db_table, opts.pk.column), [getattr(self, opts.pk.name)]) 841 888 db.db.commit() 842 setattr(self, opts.pk.column, None) 889 #jgd 890 #setattr(self, opts.pk.column, None) 891 setattr(self, opts.pk.name, None) 843 892 for f in opts.fields: 844 if isinstance(f, FileField) and getattr(self, f.column): 893 #jgd 894 #if isinstance(f, FileField) and getattr(self, f.column): 895 if isinstance(f, FileField) and getattr(self, f.name): 845 896 file_name = getattr(self, 'get_%s_filename' % f.name)() 846 897 # If the file exists and no other object of this type references it, 847 898 # delete it from the filesystem. … … 856 907 self._next_in_order_cache = opts.get_model_module().get_object(order_by=('_order',), 857 908 where=['_order > (SELECT _order FROM %s WHERE %s=%%s)' % (opts.db_table, opts.pk.column), 858 909 '%s=%%s' % order_field.column], limit=1, 859 params=[getattr(self, opts.pk.column), getattr(self, order_field.column)]) 910 #jgd 911 #params=[getattr(self, opts.pk.column), getattr(self, order_field.column)]) 912 params=[getattr(self, opts.pk.name), getattr(self, order_field.name)]) 860 913 return self._next_in_order_cache 861 914 862 915 def method_get_previous_in_order(opts, order_field, self): … … 873 926 def method_get_many_to_one(field_with_rel, self): 874 927 cache_var = field_with_rel.get_cache_name() 875 928 if not hasattr(self, cache_var): 876 val = getattr(self, field_with_rel.column) 929 #jgd 930 #val = getattr(self, field_with_rel.column) 931 val = getattr(self, field_with_rel.name) 877 932 mod = field_with_rel.rel.to.get_model_module() 878 933 if val is None: 879 934 raise getattr(mod, '%sDoesNotExist' % field_with_rel.rel.to.object_name) … … 893 948 field_with_rel.get_m2m_db_table(self._meta), rel.pk.column, 894 949 rel.object_name.lower(), self._meta.object_name.lower(), rel.get_order_sql('a')) 895 950 cursor = db.db.cursor() 896 cursor.execute(sql, [getattr(self, self._meta.pk.column)]) 951 #jgd 952 #cursor.execute(sql, [getattr(self, self._meta.pk.column)]) 953 cursor.execute(sql, [getattr(self, self._meta.pk.name)]) 897 954 setattr(self, cache_var, [getattr(mod, rel.object_name)(*row) for row in cursor.fetchall()]) 898 955 return getattr(self, cache_var) 899 956 … … 914 971 rel = rel_field.rel.to 915 972 m2m_table = rel_field.get_m2m_db_table(self._meta) 916 973 cursor = db.db.cursor() 917 this_id = getattr(self, self._meta.pk.column) 974 #jgd 975 #this_id = getattr(self, self._meta.pk.column) 976 this_id = getattr(self, self._meta.pk.name) 918 977 if ids_to_delete: 919 978 sql = "DELETE FROM %s WHERE %s_id = %%s AND %s_id IN (%s)" % (m2m_table, self._meta.object_name.lower(), rel.object_name.lower(), ','.join(map(str, ids_to_delete))) 920 979 cursor.execute(sql, [this_id]) … … 954 1013 # Handles related many-to-many object retrieval. 955 1014 # Examples: Album.get_song(), Album.get_song_list(), Album.get_song_count() 956 1015 def method_get_related_many_to_many(method_name, opts, rel_mod, rel_field, self, **kwargs): 957 kwargs['%s__%s__exact' % (rel_field.name, opts.pk.name)] = getattr(self, opts.pk.column) 1016 #jgd 1017 #kwargs['%s__%s__exact' % (rel_field.name, opts.pk.name)] = getattr(self, opts.pk.column) 1018 kwargs['%s__%s__exact' % (rel_field.name, opts.pk.name)] = getattr(self, opts.pk.name) 958 1019 return getattr(rel_mod, method_name)(**kwargs) 959 1020 960 1021 # Handles setting many-to-many related objects. … … 963 1024 id_list = map(int, id_list) # normalize to integers 964 1025 rel = rel_field.rel.to 965 1026 m2m_table = rel_field.get_m2m_db_table(rel_opts) 966 this_id = getattr(self, self._meta.pk.column) 1027 #jgd 1028 #this_id = getattr(self, self._meta.pk.column) 1029 this_id = getattr(self, self._meta.pk.name) 967 1030 cursor = db.db.cursor() 968 1031 cursor.execute("DELETE FROM %s WHERE %s_id = %%s" % (m2m_table, rel.object_name.lower()), [this_id]) 969 1032 sql = "INSERT INTO %s (%s_id, %s_id) VALUES (%%s, %%s)" % (m2m_table, rel.object_name.lower(), rel_opts.object_name.lower()) … … 1000 1063 # CHOICE-RELATED METHODS ################### 1001 1064 1002 1065 def method_get_display_value(field, self): 1003 value = getattr(self, field.column) 1066 #jgd 1067 #value = getattr(self, field.column) 1068 value = getattr(self, field.name) 1004 1069 return dict(field.choices).get(value, value) 1005 1070 1006 1071 # FILE-RELATED METHODS ##################### … … 1151 1216 1152 1217 # 'fields' is a list of field names to fetch. 1153 1218 try: 1154 fields = [opts.get_field(f).column for f in kwargs.pop('fields')] 1219 #jgd 1220 #fields = [opts.get_field(f).column for f in kwargs.pop('fields')] 1221 fields = [opts.get_field(f).name for f in kwargs.pop('fields')] 1155 1222 except KeyError: # Default to all fields. 1156 fields = [f.column for f in opts.fields] 1223 #jgd 1224 #fields = [f.column for f in opts.fields] 1225 fields = [f.name for f in opts.fields] 1157 1226 1158 1227 cursor = db.db.cursor() 1159 1228 _, sql, params = function_get_sql_clause(opts, **kwargs) … … 1203 1272 # table_count is used to ensure table aliases are unique. 1204 1273 tables, join_where, where, params = [], [], [], [] 1205 1274 for kwarg, kwarg_value in kwarg_items: 1275 #jgd 1276 #print "kw: " + kwarg, kwarg_value 1206 1277 if kwarg in ('order_by', 'limit', 'offset', 'select_related', 'distinct', 'select', 'tables', 'where', 'params'): 1207 1278 continue 1208 1279 if kwarg_value is None: … … 1218 1289 lookup_list = kwarg.split(LOOKUP_SEPARATOR) 1219 1290 # pk="value" is shorthand for (primary key)__exact="value" 1220 1291 if lookup_list[-1] == 'pk': 1292 #jgd 1293 #print "looking up pk" 1221 1294 if opts.pk.rel: 1295 #print "pk rel" 1222 1296 lookup_list = lookup_list[:-1] + [opts.pk.name, opts.pk.rel.field_name, 'exact'] 1223 1297 else: 1298 #print "pk no rel" 1224 1299 lookup_list = lookup_list[:-1] + [opts.pk.name, 'exact'] 1225 1300 if len(lookup_list) == 1: 1301 #jgd 1302 #print "len(lookup_list) == 1" 1226 1303 _throw_bad_kwarg_error(kwarg) 1227 1304 lookup_type = lookup_list.pop() 1228 1305 current_opts = opts # We'll be overwriting this, so keep a reference to the original opts. 1229 1306 current_table_alias = current_opts.db_table 1230 1307 param_required = False 1231 1308 while lookup_list or param_required: 1309 #jgd 1310 #print "looking up " + str(lookup_list) 1232 1311 table_count += 1 1233 1312 try: 1234 1313 # "current" is a piece of the lookup list. For example, in … … 1240 1319 # If we're here, lookup_list is empty but param_required 1241 1320 # is set to True, which means the kwarg was bad. 1242 1321 # Example: choices.get_list(poll__exact='foo') 1322 #jgd 1323 #print "bad lookup pop" 1243 1324 _throw_bad_kwarg_error(kwarg) 1244 1325 # Try many-to-many relationships first... 1245 1326 for f in current_opts.many_to_many: 1327 #jgd 1328 #print "trying many to many " + str(f.name) 1246 1329 if f.name == current: 1330 #jgd 1331 #print "found m-to-m rel" 1247 1332 rel_table_alias = 't%s' % table_count 1248 1333 table_count += 1 1249 1334 tables.append('%s %s' % (f.get_m2m_db_table(current_opts), rel_table_alias)) … … 1252 1337 # Optimization: In the case of primary-key lookups, we 1253 1338 # don't have to do an extra join. 1254 1339 if lookup_list and lookup_list[0] == f.rel.to.pk.name and lookup_type == 'exact': 1340 #jgd 1341 #print "doing m-to-m pk lookup" 1255 1342 where.append(_get_where_clause(lookup_type, rel_table_alias+'.', 1256 1343 f.rel.to.object_name.lower()+'_id', kwarg_value)) 1257 1344 params.extend(f.get_db_prep_lookup(lookup_type, kwarg_value)) 1258 1345 lookup_list.pop() 1259 1346 param_required = False 1260 1347 else: 1348 #jgd 1349 #print "doing m-to-m regular lookup" 1261 1350 new_table_alias = 't%s' % table_count 1262 1351 tables.append('%s %s' % (f.rel.to.db_table, new_table_alias)) 1263 1352 join_where.append('%s.%s_id = %s.%s' % (rel_table_alias, f.rel.to.object_name.lower(), 1264 1353 new_table_alias, f.rel.to.pk.column)) 1265 1354 current_table_alias = new_table_alias 1266 1355 param_required = True 1356 #jgd 1357 #print "switching opts to be relative to m-to-m join target and jumping to next lookup" 1267 1358 current_opts = f.rel.to 1268 1359 raise StopIteration 1269 1360 for f in current_opts.fields: 1361 #jgd 1362 #print "trying one to many " + str(f.name) 1363 1270 1364 # Try many-to-one relationships... 1271 1365 if f.rel and f.name == current: 1366 #jgd 1367 #print "found 1-to-m rel " 1272 1368 # Optimization: In the case of primary-key lookups, we 1273 1369 # don't have to do an extra join. 1274 1370 if lookup_list and lookup_list[0] == f.rel.to.pk.name and lookup_type == 'exact': 1371 #jgd 1372 #print "pk look up" 1275 1373 where.append(_get_where_clause(lookup_type, current_table_alias+'.', f.column, kwarg_value)) 1276 1374 params.extend(f.get_db_prep_lookup(lookup_type, kwarg_value)) 1277 1375 lookup_list.pop() … … 1280 1378 # because we don't want to do a join. We just want to find out 1281 1379 # whether the foreign key field is NULL. 1282 1380 elif lookup_type == 'isnull' and not lookup_list: 1381 #jgd 1382 #print "isnull lookup" 1283 1383 where.append(_get_where_clause(lookup_type, current_table_alias+'.', f.column, kwarg_value)) 1284 1384 params.extend(f.get_db_prep_lookup(lookup_type, kwarg_value)) 1285 1385 else: 1386 #jgd 1387 #print "regular 1-to-m lookup" 1286 1388 new_table_alias = 't%s' % table_count 1287 1389 tables.append('%s %s' % (f.rel.to.db_table, new_table_alias)) 1288 1390 join_where.append('%s.%s = %s.%s' % (current_table_alias, f.column, \ 1289 1391 new_table_alias, f.rel.to.pk.column)) 1290 1392 current_table_alias = new_table_alias 1291 1393 param_required = True 1394 #jgd 1395 #print "switching opts to be relative to 1-to-m join target and jumping to next lookup" 1292 1396 current_opts = f.rel.to 1293 1397 raise StopIteration 1294 1398 # Try direct field-name lookups... 1295 1399 if f.name == current: 1400 #jgd 1401 #print "found direct field name" 1296 1402 where.append(_get_where_clause(lookup_type, current_table_alias+'.', f.column, kwarg_value)) 1297 1403 params.extend(f.get_db_prep_lookup(lookup_type, kwarg_value)) 1298 1404 param_required = False 1299 1405 raise StopIteration 1300 1406 # If we haven't hit StopIteration at this point, "current" must be 1301 1407 # an invalid lookup, so raise an exception. 1408 #jgd 1409 #print "can't figure it out" 1302 1410 _throw_bad_kwarg_error(kwarg) 1303 1411 except StopIteration: 1304 1412 continue … … 1363 1471 kwargs['where'] = ["%s.%s IN (%s)" % (opts.db_table, opts.pk.column, ",".join(['%s'] * len(id_list)))] 1364 1472 kwargs['params'] = id_list 1365 1473 obj_list = function_get_list(opts, klass, **kwargs) 1366 return dict([(getattr(o, opts.pk.column), o) for o in obj_list]) 1474 #jgd 1475 #return dict([(getattr(o, opts.pk.column), o) for o in obj_list]) 1476 return dict([(getattr(o, opts.pk.name), o) for o in obj_list]) 1367 1477 1368 1478 def function_get_latest(opts, klass, does_not_exist_exception, **kwargs): 1369 1479 kwargs['order_by'] = ('-' + opts.get_latest_by,) … … 1433 1543 lookup_kwargs = opts.one_to_one_field.rel.limit_choices_to 1434 1544 lookup_kwargs['%s__exact' % opts.one_to_one_field.rel.field_name] = obj_key 1435 1545 _ = opts.one_to_one_field.rel.to.get_model_module().get_object(**lookup_kwargs) 1436 params = dict([(f.column, f.get_default()) for f in opts.fields]) 1437 params[opts.pk.column] = obj_key 1546 1547 #jgd 1548 #params = dict([(f.column, f.get_default()) for f in opts.fields]) 1549 #params[opts.pk.column] = obj_key 1550 params = dict([(f.name, f.get_default()) for f in opts.fields]) 1551 params[opts.pk.name] = obj_key 1438 1552 self.original_object = opts.get_model_module().Klass(**params) 1439 1553 else: 1440 1554 raise … … 1469 1583 for f in opts.fields: 1470 1584 # Fields with auto_now_add are another special case; they should keep 1471 1585 # their original value in the change stage. 1586 1587 #jgd 1472 1588 if change and getattr(f, 'auto_now_add', False): 1473 params[f.column] = getattr(self.original_object, f.name) 1589 #params[f.column] = getattr(self.original_object, f.name) 1590 params[f.name] = getattr(self.original_object, f.name) 1474 1591 else: 1475 params[f.column] = f.get_manipulator_new_data(new_data) 1592 #params[f.column] = f.get_manipulator_new_data(new_data) 1593 params[f.name] = f.get_manipulator_new_data(new_data) 1476 1594 1477 1595 if change: 1478 params[opts.pk.column] = self.obj_key 1596 #params[opts.pk.column] = self.obj_key 1597 params[opts.pk.name] = self.obj_key 1479 1598 1480 1599 # First, save the basic object itself. 1481 1600 new_object = klass(**params) … … 1490 1609 if change: 1491 1610 self.fields_added, self.fields_changed, self.fields_deleted = [], [], [] 1492 1611 for f in opts.fields: 1493 if not f.primary_key and str(getattr(self.original_object, f.column)) != str(getattr(new_object, f.column)): 1612 #jgd 1613 #if not f.primary_key and str(getattr(self.original_object, f.column)) != str(getattr(new_object, f.column)): 1614 if not f.primary_key and str(getattr(self.original_object, f.name)) != str(getattr(new_object, f.name)): 1615 #jgd really want verbose_name here? 1494 1616 self.fields_changed.append(f.verbose_name) 1495 1617 1496 1618 # Save many-to-many objects. Example: Poll.set_sites() … … 1541 1663 # case, because they'll be dealt with later. 1542 1664 if change and (isinstance(f, FileField) or not f.editable): 1543 1665 if rel_new_data.get(rel_opts.pk.name, False) and rel_new_data[rel_opts.pk.name][0]: 1544 params[f.column] = getattr(old_rel_obj, f.column) 1666 #jgd 1667 #params[f.column] = getattr(old_rel_obj, f.column) 1668 params[f.name] = getattr(old_rel_obj, f.name) 1545 1669 else: 1546 params[f.column] = f.get_default() 1670 #jgd 1671 #params[f.column] = f.get_default() 1672 params[f.name] = f.get_default() 1547 1673 elif f == rel_field: 1548 params[f.column] = getattr(new_object, rel_field.rel.field_name) 1674 #jgd 1675 #params[f.column] = getattr(new_object, rel_field.rel.field_name) 1676 params[f.name] = getattr(new_object, rel_field.rel.field_name) 1549 1677 elif add and isinstance(f, AutoField): 1550 params[f.column] = None 1678 #jgd 1679 #params[f.column] = None 1680 params[f.name] = None 1551 1681 else: 1552 params[f.column] = f.get_manipulator_new_data(rel_new_data, rel=True) 1682 #jgd 1683 #params[f.column] = f.get_manipulator_new_data(rel_new_data, rel=True) 1684 params[f.name] = f.get_manipulator_new_data(rel_new_data, rel=True) 1553 1685 # Related links are a special case, because we have to 1554 1686 # manually set the "content_type_id" and "object_id" fields. 1555 1687 if opts.has_related_links and rel_opts.module_name == 'relatedlinks': … … 1575 1707 self.fields_added.append('%s "%r"' % (rel_opts.verbose_name, new_rel_obj)) 1576 1708 else: 1577 1709 for f in rel_opts.fields: 1578 if not f.primary_key and f != rel_field and str(getattr(old_rel_obj, f.column)) != str(getattr(new_rel_obj, f.column)): 1710 #jgd 1711 #if not f.primary_key and f != rel_field and str(getattr(old_rel_obj, f.column)) != str(getattr(new_rel_obj, f.column)): 1712 if not f.primary_key and f != rel_field and str(getattr(old_rel_obj, f.name)) != str(getattr(new_rel_obj, f.name)): 1579 1713 self.fields_changed.append('%s for %s "%r"' % (f.verbose_name, rel_opts.verbose_name, new_rel_obj)) 1580 1714 1581 1715 # Save many-to-many objects. … … 1606 1740 else: 1607 1741 kwargs = {'%s__iexact' % field_name_list[0]: field_data} 1608 1742 for f in field_list[1:]: 1609 field_val = all_data.get(f.column, None) 1743 #jgd 1744 #field_val = all_data.get(f.column, None) 1745 field_val = all_data.get(f.name, None) 1610 1746 if field_val is None: 1611 1747 # This will be caught by another validator, assuming the field 1612 1748 # doesn't have blank=True. … … 1620 1756 old_obj = mod.get_object(**kwargs) 1621 1757 except ObjectDoesNotExist: 1622 1758 return 1623 if hasattr(self, 'original_object') and getattr(self.original_object, opts.pk.column) == getattr(old_obj, opts.pk.column): 1759 #jgd 1760 #if hasattr(self, 'original_object') and getattr(self.original_object, opts.pk.column) == getattr(old_obj, opts.pk.column): 1761 if hasattr(self, 'original_object') and getattr(self.original_object, opts.pk.name) == getattr(old_obj, opts.pk.name): 1624 1762 pass 1625 1763 else: 1626 1764 raise validators.ValidationError, "%s with this %s already exists for the given %s." % \ … … 1646 1784 except ObjectDoesNotExist: 1647 1785 return 1648 1786 else: 1649 if hasattr(self, 'original_object') and getattr(self.original_object, opts.pk.column) == getattr(old_obj, opts.pk.column): 1787 #jgd 1788 #if hasattr(self, 'original_object') and getattr(self.original_object, opts.pk.column) == getattr(old_obj, opts.pk.column): 1789 if hasattr(self, 'original_object') and getattr(self.original_object, opts.pk.name) == getattr(old_obj, opts.pk.name): 1650 1790 pass 1651 1791 else: 1652 1792 format_string = (lookup_type == 'date') and '%B %d, %Y' or '%B %Y'