Carl Meyer  committed 7ece844 Merge


  • Participants
  • Parent commits 7bf29f1, 37887e8

Comments (0)

Files changed (5)

 tip (unreleased)
+- Added ``InheritanceManager.get_subclass()``. Thanks smacker.
 1.0.0 (2011.06.16)
     nearby_places = Place.objects.select_subclasses("restaurant")
     # restaurants will be Restaurant instances, bars will still be Place instances
-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.
+``InheritanceManager`` also provides a subclass-fetching alternative to the
+``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()`` or ``get_subclass()``,
+an ``InheritanceManager`` behaves identically to a normal ``Manager``; so
+it's safe to use as your default manager for the model.
 .. note::
     ``InheritanceManager`` currently only supports a single level of model

File model_utils/

     def select_subclasses(self, *subclasses):
         return self.get_query_set().select_subclasses(*subclasses)
+    def get_subclass(self, *args, **kwargs):
+        return self.get_query_set().select_subclasses().get(*args, **kwargs)
 class InheritanceCastMixin(object):
     def cast(self):

File model_utils/tests/

+        def test_get_subclass(self):
+            self.assertEquals(
+                self.get_manager().get_subclass(,
+                self.child1)
     class InheritanceManagerRelatedTests(InheritanceManagerTests):
         def setUp(self):