Ticket #757: pk_save.diff
File pk_save.diff, 1.6 KB (added by , 19 years ago) |
---|
-
django/core/meta/__init__.py
796 796 record_exists = False 797 797 if not pk_set or not record_exists: 798 798 field_names = [f.column for f in opts.fields if not isinstance(f, AutoField)] 799 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)] 800 801 if pk_set: 802 field_names += [f.column for f in opts.fields if isinstance(f, AutoField)] 803 db_values += [f.get_db_prep_save(f.pre_save(getattr(self, f.column), True)) for f in opts.fields if isinstance(f, AutoField)] 804 799 805 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)] 806 801 807 if opts.order_with_respect_to: 802 808 field_names.append('_order') 803 809 # TODO: This assumes the database supports subqueries. … … 806 812 db_values.append(getattr(self, opts.order_with_respect_to.column)) 807 813 cursor.execute("INSERT INTO %s (%s) VALUES (%s)" % (opts.db_table, 808 814 ','.join(field_names), ','.join(placeholders)), db_values) 809 if opts.has_auto_field :815 if opts.has_auto_field and not pk_set: 810 816 setattr(self, opts.pk.column, db.get_last_insert_id(cursor, opts.db_table, opts.pk.column)) 811 817 db.db.commit() 812 818 # Run any post-save hooks.