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
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Good luck & Happy New Year.