On Tue, Mar 10, 2009 at 9:44 PM, Michael Strickland <[email protected]> wrote:
> So I've actually run into a new problem: declaring the permalink for
> only the inherited models works fine, but whenever I query the
> database using the base model's manager (so I can get results from all
> of the inherited models), the resulting objects that are returned use
> the base model's permalink method, instead of the appropriate
> inherited model's method.

This is a small variation on a common question, usually phrased as
"how do I get a base class's manager to return instances of
subclasses?" If you look through the archives, you'll see this comes
up every few days or so.

The short answer is that for a number of reasons, most notably
performance, managers always return instances of their associated
models, regardless of class hierarchy. So `Base.objects.all()` always
returns `Base` instances, and `Child.objects.all()` always returns
`Child` instances. Again, search the archives if you want more details
of why this is.

Now, the long answer is that there are a number of ways to track which
"type" of child class a base class "really" is. I've used a variation
of http://www.djangosnippets.org/snippets/1187/ in the past and been
relatively happy with it. You might also try just doing that kind of
work in your base class's `get_absolute_url()` method if that's the
only bit you need.

Jacob

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to