diff --git a/django/db/models/manager.py b/django/db/models/manager.py
index 8da8af4..f662131 100644
a
|
b
|
class Manager(object):
|
139 | 139 | def extra(self, *args, **kwargs): |
140 | 140 | return self.get_query_set().extra(*args, **kwargs) |
141 | 141 | |
| 142 | def first(self, *args, **kwargs): |
| 143 | return self.get_query_set().first(*args, **kwargs) |
| 144 | |
142 | 145 | def get(self, *args, **kwargs): |
143 | 146 | return self.get_query_set().get(*args, **kwargs) |
144 | 147 | |
diff --git a/django/db/models/query.py b/django/db/models/query.py
index 130be9a..978009e 100644
a
|
b
|
class QuerySet(object):
|
363 | 363 | |
364 | 364 | return self.query.get_count(using=self.db) |
365 | 365 | |
| 366 | def first(self, *args, **kwargs): |
| 367 | """ |
| 368 | Performs the query and returns the first object matching the given |
| 369 | keyword arguments or None if no match is found. |
| 370 | """ |
| 371 | clone = self.filter(*args, **kwargs) |
| 372 | if self.query.can_filter(): |
| 373 | clone = clone.order_by() |
| 374 | if clone: |
| 375 | return clone._result_cache[0] |
| 376 | return None |
| 377 | |
366 | 378 | def get(self, *args, **kwargs): |
367 | 379 | """ |
368 | 380 | Performs the query and returns a single object matching the given |
diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt
index 295c996..409764e 100644
a
|
b
|
something *other than* a ``QuerySet``.
|
1238 | 1238 | These methods do not use a cache (see :ref:`caching-and-querysets`). Rather, |
1239 | 1239 | they query the database each time they're called. |
1240 | 1240 | |
| 1241 | first |
| 1242 | ~~~ |
| 1243 | .. method:: first(**kwargs) |
| 1244 | |
| 1245 | .. versionadded:: 1.6 |
| 1246 | |
| 1247 | Returns the first of all objects matching the given lookup parameters, which |
| 1248 | should be in the format described in `Field lookups`_. |
| 1249 | |
| 1250 | ``first()`` returns None if no object was found for the given parameters. |
| 1251 | |
| 1252 | ``first()`` returns the first object in the QuerySet when multiple objects were |
| 1253 | found, as determined by the ordering in the model or in the query. |
| 1254 | |
| 1255 | Example:: |
| 1256 | p = Person.objects.first(first_name="Paul") |
| 1257 | |
1241 | 1258 | get |
1242 | 1259 | ~~~ |
1243 | 1260 | |
diff --git a/tests/modeltests/basic/tests.py b/tests/modeltests/basic/tests.py
index 1c83b98..c66678c 100644
a
|
b
|
class ModelTest(TestCase):
|
162 | 162 | pub_date__month=7, |
163 | 163 | ) |
164 | 164 | |
| 165 | # First should return None when no object is found |
| 166 | self.assertEqual( |
| 167 | Article.objects.first(pub_date__year=2012), |
| 168 | None, |
| 169 | ) |
| 170 | |
| 171 | # First should return the first object when multiple objects are found |
| 172 | a = Article.objects.filter(pub_date__year=2005)[0] |
| 173 | |
| 174 | self.assertEqual( |
| 175 | Article.objects.first(pub_date__year=2005), |
| 176 | a, |
| 177 | ) |
| 178 | |
165 | 179 | def test_object_creation(self): |
166 | 180 | # Create an Article. |
167 | 181 | a = Article( |