diff --git a/django/db/models/query.py b/django/db/models/query.py
index ff5289c..73d839b 100644
a
|
b
|
class QuerySet(object):
|
358 | 358 | Returns a tuple of (object, created), where created is a boolean |
359 | 359 | specifying whether an object was created. |
360 | 360 | """ |
361 | | assert kwargs, \ |
362 | | 'get_or_create() must be passed at least one keyword argument' |
363 | 361 | defaults = kwargs.pop('defaults', {}) |
364 | 362 | lookup = kwargs.copy() |
365 | 363 | for f in self.model._meta.fields: |
diff --git a/tests/modeltests/get_or_create/models.py b/tests/modeltests/get_or_create/models.py
index 14f55f8..403b6a9 100644
a
|
b
|
class Person(models.Model):
|
16 | 16 | def __unicode__(self): |
17 | 17 | return u'%s %s' % (self.first_name, self.last_name) |
18 | 18 | |
| 19 | class DefaultPerson(models.Model): |
| 20 | first_name = models.CharField(max_length=100, default="Anonymous") |
| 21 | |
19 | 22 | class ManualPrimaryKeyTest(models.Model): |
20 | 23 | id = models.IntegerField(primary_key=True) |
21 | 24 | data = models.CharField(max_length=100) |
diff --git a/tests/modeltests/get_or_create/tests.py b/tests/modeltests/get_or_create/tests.py
index 3323c88..c667801 100644
a
|
b
|
from datetime import date
|
3 | 3 | from django.db import IntegrityError |
4 | 4 | from django.test import TestCase |
5 | 5 | |
6 | | from models import Person, ManualPrimaryKeyTest |
| 6 | from models import Person, DefaultPerson, ManualPrimaryKeyTest |
7 | 7 | |
8 | 8 | |
9 | 9 | class GetOrCreateTests(TestCase): |
… |
… |
class GetOrCreateTests(TestCase):
|
50 | 50 | ManualPrimaryKeyTest.objects.get_or_create, id=1, data="Different" |
51 | 51 | ) |
52 | 52 | self.assertEqual(ManualPrimaryKeyTest.objects.get(id=1).data, "Original") |
| 53 | |
| 54 | def test_get_or_create_empty(self): |
| 55 | # If all the attributes on a model have defaults, we shouldn't |
| 56 | # need to pass any arguments. |
| 57 | try: |
| 58 | DefaultPerson.objects.get_or_create() |
| 59 | except AssertionError: |
| 60 | self.assertTrue(False) |