1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Fixed #8669 -- Use a consistent version of create() across the board for

model/field instance creation. Based on a patch from Richard Davies.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@8884 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick
2008-09-03 00:09:33 +00:00
parent 0e5faf225c
commit 85ebb91846
4 changed files with 80 additions and 28 deletions

View File

@@ -16,6 +16,10 @@ class Person(models.Model):
def __unicode__(self):
return u'%s %s' % (self.first_name, self.last_name)
class ManualPrimaryKeyTest(models.Model):
id = models.IntegerField(primary_key=True)
data = models.CharField(max_length=100)
__test__ = {'API_TESTS':"""
# Acting as a divine being, create an Person.
>>> from datetime import date
@@ -61,4 +65,19 @@ False
... else:
... print "Fail with %s" % type(e)
Pass
# If you specify an existing primary key, but different other fields, then you
# will get an error and data will not be updated.
>>> m = ManualPrimaryKeyTest(id=1, data='Original')
>>> m.save()
>>> try:
... m, created = ManualPrimaryKeyTest.objects.get_or_create(id=1, data='Different')
... except Exception, e:
... if isinstance(e, IntegrityError):
... print "Pass"
... else:
... print "Fail with %s" % type(e)
Pass
>>> ManualPrimaryKeyTest.objects.get(id=1).data == 'Original'
True
"""}