Skip to content

Commit

Permalink
test and docs for get_subclass
Browse files Browse the repository at this point in the history
  • Loading branch information
smacker committed Oct 26, 2011
1 parent 9ac5877 commit b06ba20
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.rst
Expand Up @@ -263,6 +263,11 @@ be returned as their actual type, you can pass subclass names to
nearby_places = Place.objects.select_subclasses("restaurant")
# restaurants will be Restaurant instances, bars will still be Place instances

Also it provides syntax sugar for `get()` method::
place = Place.objects.get_subclass(id=some_id)
# "place" will automatically be an instance of Place, Restaurant, or Bar

If you don't explicitly call ``select_subclasses()``, an ``InheritanceManager``
behaves identically to a normal ``Manager``; so it's safe to use as your
default manager for the model.
Expand Down
5 changes: 5 additions & 0 deletions model_utils/tests/tests.py
Expand Up @@ -353,6 +353,11 @@ def test_select_specific_subclasses(self):
set([self.child1,
InheritanceManagerTestParent(pk=self.child2.pk)]))

def test_get_subclass(self):
self.assertEquals(
self.get_manager().get_subclass(pk=self.child1.pk),
self.child1)


class InheritanceManagerRelatedTests(InheritanceManagerTests):
def setUp(self):
Expand Down

0 comments on commit b06ba20

Please sign in to comment.