Hi, I'm having some trouble with what I would have thought would be a simple query. Working with the multi-table inheritance examples Django gives:
class Place(models.Model): name = models.CharField(max_length=50) address = models.CharField(max_length=80) class Restaurant(Place): serves_hot_dogs = models.BooleanField() serves_pizza = models.BooleanField() how do I get all the Places that are also Restaurants? Obviously I can do Restaurant.objects.all(), but that returns a set of Restaurants, whereas I want the set of Places that those Restaurants are linked to. I've tried (the equivalent in my app of) the following but it generates an InternalError: Place.objects.filter(restaurant__isnull=False) The only surefire way of getting what I want would be to do something like: [r.place_ptr for r in Restaurant.objects.all()] But this presumably incurs inefficiencies of using python rather than SQL. So first question: is the above possible in a more efficient manner? ----------- I have a second question relating to this. The reason WHY I want to do the above is because of Django's problem with serializing objects of class Restaurant, whereby it only serializes the local fields. The suggested solution in the documentation is: all_objects = list(Restaurant.objects.all()) + list(Place.objects.all ()) data = serializers.serialize('xml', all_objects) But this doesn't do at all what I would want; it in fact seems to do exactly what it looks like it would do: serialize a list that starts with the Restaurant objects (with their local fields), then a FULL list of all the Place objects. Question: am I misreading/miscopy-and-pasteing the above code; does it in fact do something else?, or is it actually MEANT to make the awkward list of "all Restaurants and all Places"? If I can't find a solution using multi-table inheritance then I imagine I'm going to have to use an abstract base class (which would involve rethinking my architecture). Thanks in advance and all the best James Fisher --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---