Hi Bjørn, Sure. In this case you would need a discriminator attribute on Place. I'm thinking of code along the lines of:
class Place(models.Model): ... discriminator = models.CharField(maxlength=50) def save(self): self.discriminator = self.__class__.__name__.lower() models.Model.save(self) def autocast(self): return self.getattr(self.discriminator) Then in your view: def detail_view(id): place = Place.objects.get(id).autocast() return render_to_response( "templates/place_%s.html" % place.discriminator, place=place) I'd be pleased to see Django require discriminator attributes on superclasses, and then automagically retrieve the correct subclasses at the correct times. It seems to work well enough in ORMs such as Hibernate. However, I think I could happily live with Malcolm's proposal too, even if it means writing code like the above every now-and-then. Alan On 8/8/06, Bjørn Stabell <[EMAIL PROTECTED]> wrote: > > Okay, I've got one more question. If we're not going to support > querying for an object's real type, it becomes quite cumbersome to do > anything polymorphically, which kind-of is the point of > object-orientation. > > For example, to use the same URI spec & view for all the subtypes. > > OPTION 1: lots of if-then-else's > > def detail_view(id): > place = Place.objects.get(id) > if place.isinstance(Place): model_name = 'Place' > elif place.isinstance(Restaurant): model_name = 'Restaurant' > ... > return render_to_response("templates/place_%s.html" % model_name, > place) > > OPTION 2: embed the type in the URI > > def detail_view(model_name, id): > ... # or map to a different view altogether > > Neither seem like very good solutions to me. Am I missing something? > > > > > -- Alan Green [EMAIL PROTECTED] - http://bright-green.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers -~----------~----~----~----~------~----~------~--~---