Alistair Marshall wrote:
> 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.
>
I don't know if it's clever or stupid, but this is what I have done in a
similar situation:
#-------------------------------------------------
class Item(models.Model):
....
typecode = models.CharField(max_length=30, editable=False)
def save(self, force_insert=False, force_update=False):
self.typecode = self.__class__.__name__.lower()
super(Item, self).save(force_insert, force_update)
def get_related(self):
return
self.__class__.__dict__[self.typecode].related.model.objects.get(id=self.id)
class SubItem(Item):
....
#-------------------------------------------------
If called from an Item instance, 'get_related' will return the related
SubItem instance. In your case, you would first get the 'restaurant',
then call it's 'get_workforce'. Still working on it, so there may be
unforseen issues.
Regards
G.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---