Changeset 1511
- Timestamp:
- 11/30/05 21:06:30 (3 years ago)
- Files:
-
- django/trunk/AUTHORS (modified) (1 diff)
- django/trunk/django/core/meta/__init__.py (modified) (2 diffs)
- django/trunk/tests/testapp/models/basic.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/AUTHORS
r1509 r1511 88 88 ye7cakf02@sneakemail.com 89 89 90 91 90 A big THANK YOU goes to: 92 91 django/trunk/django/core/meta/__init__.py
r1508 r1511 1010 1010 if not pk_set or not record_exists: 1011 1011 field_names = [db.db.quote_name(f.column) for f in opts.fields if not isinstance(f, AutoField)] 1012 db_values = [f.get_db_prep_save(f.pre_save(getattr(self, f.attname), True)) for f in opts.fields if not isinstance(f, AutoField)] 1013 # If the PK has been manually set we must respect that 1014 if pk_set: 1015 field_names += [f.column for f in opts.fields if isinstance(f, AutoField)] 1016 db_values += [f.get_db_prep_save(f.pre_save(getattr(self, f.column), True)) for f in opts.fields if isinstance(f, AutoField)] 1012 1017 placeholders = ['%s'] * len(field_names) 1013 db_values = [f.get_db_prep_save(f.pre_save(getattr(self, f.attname), True)) for f in opts.fields if not isinstance(f, AutoField)]1014 1018 if opts.order_with_respect_to: 1015 1019 field_names.append(db.db.quote_name('_order')) … … 1021 1025 (db.db.quote_name(opts.db_table), ','.join(field_names), 1022 1026 ','.join(placeholders)), db_values) 1023 if opts.has_auto_field :1027 if opts.has_auto_field and not pk_set: 1024 1028 setattr(self, opts.pk.attname, db.get_last_insert_id(cursor, opts.db_table, opts.pk.column)) 1025 1029 db.db.commit() django/trunk/tests/testapp/models/basic.py
r1033 r1511 158 158 >>> a8.id 159 159 8L 160 161 # You can manually specify the primary key when creating a new objet 162 >>> a101 = articles.Article(id=101, headline='Article 101', pub_date=datetime(2005, 7, 31, 12, 30, 45)) 163 >>> a101.save() 164 >>> a101 = articles.get_object(pk=101) 165 >>> a101.headline 166 'Article 101' 167 160 168 """ 161 169
