Ticket #15304: 15304-pk-type-r15539.diff

File 15304-pk-type-r15539.diff, 1.9 KB (added by Tai Lee, 13 years ago)
  • docs/intro/tutorial01.txt

     
    534534    # Save the object into the database. You have to call save() explicitly.
    535535    >>> p.save()
    536536
    537     # Now it has an ID. Note that this might say "1L" instead of "1", depending
    538     # on which database you're using. That's no biggie; it just means your
    539     # database backend prefers to return integers as Python long integer
    540     # objects.
     537    # Now it has an ID.
    541538    >>> p.id
    542539    1
    543540
  • tests/regressiontests/model_regress/tests.py

     
    163163            1
    164164        )
    165165
     166    def test_pk_type(self):
     167        # Make sure that the primary key value of newly created objects is the
     168        # same type as existing objects.
     169        p = Party.objects.create()
     170        p2 = Party.objects.get(pk=p.pk)
     171        self.assertEqual(type(p.pk), type(p2.pk))
     172
    166173class ModelValidationTest(TestCase):
    167174    def test_pk_validation(self):
    168175        one = NonAutoPK.objects.create(name="one")
  • django/db/models/base.py

     
    556556                    result = manager._insert([(meta.pk, connection.ops.pk_default_value())], return_id=update_pk, raw_values=True, using=using)
    557557
    558558                if update_pk:
    559                     setattr(self, meta.pk.attname, result)
     559                    setattr(self, meta.pk.attname, meta.auto_field.to_python(result))
    560560            transaction.commit_unless_managed(using=using)
    561561
    562562        # Store the database on which the object was saved
Back to Top