Maniac wrote:
Jacob Kaplan-Moss wrote:
If I ask for places, give me a list of places and don't bother
looking up restaurants. So:: ``place_instance.description`` should
raise an ``AttributeError`` regardless if weather or not it is
actually a restaurant.
Why? This is not how duck typing works all over the Python: if the
object does have an attribute you shouldn't do nothing special (like
casting) to get it.
Agreed. Instead, I think the explicitness Jacob wants should actually
be a factor of the Manager class in question, particularly because the
biggest impact is on the amount of database work involved (to join or
not to join). Maybe the default manager doesn't join, it just returns
everything in terms of the class that it is attached to. But you could
explicitly create a "PolymorphicManager" that can (and does) join
subclassed models. Something like:
``
app_objects = managers.PolymorphicManager(Place, Restaurant,
ItalianRestaurant)
``
This also makes it explicit which classes are participating in a join,
rather than potentially joining a large number of installed model classes.
--
--Max Battcher--
http://www.worldmaker.net/