On 07/11/2008, at 3:01 AM, Alistair Marshall wrote:
On Nov 6, 2:22 pm, Thomas Guettler <[EMAIL PROTECTED]> wrote: > If all worker classes (cook, waiter, ...) are subclassed from Worker, > something like this should work: Worker.objects.filter(workplace=...) > Unfortunately the function that each child will run is a bit more complicated than just listing workers. It involves output of different equations depending on the class. Think of it like calculating rents for the different Places and the rate of rent depends on both the size of the Place and the type of the place (ie a charity shop might have a lower rate) As I said, I have the function named the same in each child class but I need to be able to access it from a list of all the Places. My current thinking is just a long list of try, except: statements attempting to call the subclass from the Place model but this feels hacky and un-clean. Alistair Maybe something like this might work: Store the content type of the child in the parent model. class Place(models.Model): place_type = models.ForeignKey(ContentType) def get_workforce(self): child = self.place_type.model_class().objects.get (place_ptr=self.id) child.get_workforce() Pawel. --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---