I've gotten model inheritance working just fine, but was hoping
someone could confirm the best way to access the model.

When I have a Base model which has a ForeignKey to a parent table, and
that base model has inherited models after it, how can I refer to only
one name when referencing the parent model.

As an example:

class Base(models.Model):
    parent = models.ForeignKey(Model1)

    class Meta:
        abstract = True

    def basemethod():
      print "hello"

class ChildA(Base):
    pass

class ChildB(Base):
    pass

p1 = Model1()
p1.save
x = ChildA()
x.parent = P1
x.save()

p2 = Model1()
p2.save()
y = ChildB()
y.parent = P1
y.save()

Now, I want to access the children from the parent, but I don't want
to have to know what base class they are, is there a way to do that?
Right now I'm using a property which figures it out based on some
other fields, but would love to be able to say

p = Parent1.objects.get(id=1)
p.child.basemethod()

Is this possible?

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.

Reply via email to