Link to home
Start Free TrialLog in
Avatar of mannsi
mannsi

asked on

Python, referencing a sub-class

Hello experts,

I am having a problem that I hope there is an solution to.

I have a base class called Document. I then have few sub-classes of Document (Book, Magazine, ...). My problem lies in the fact that a Book has an author attribute but a Magazine doesn't. So when I do:

documents = bookModel.Document.objects.all()

for document in documents:
    print document.author

I get nothing since the base class doesn't have an author attribute.

Do these instanced of a base class not know they are really  implemented as sub-classes ?

I hope I am being clear enough
ASKER CERTIFIED SOLUTION
Avatar of HonorGod
HonorGod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the grade & points.

Good luck & Happy New Year.