On Nov 7, 4:19 pm, Gerard flanagan <[EMAIL PROTECTED]> wrote:
> I don't know if it's clever or stupid, but this is what I have done in a
> similar situation:
>

It appears to be a nice solution - it throws an error If I try to
get_related() on a generic non-specialised place rather than just
returning itself, but I don't think that will be a problem for this
application.

-- update actually this can be fixed with a try except statement:
#-------------------------------------------------
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):
    try:
      return
self.__class__.__dict__[self.typecode].related.model.objects.get(id=self.id)
    except:
      return self

class SubItem(Item):
     ....

#-------------------------------------------------

Thanks

Alistair

--
Alistair Marshall

www.thatscottishengineer.co.uk
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to