53đź‘Ť
âś…
You can use hasattr()
to check to see if model has the documents property.
if hasattr(self.model, 'documents'):
doStuff(self.model.documents)
However, this answer points out that some people feel the “easier to ask for forgiveness than permission” approach is better practice.
try:
doStuff(self.model.documents)
except AttributeError:
otherStuff()
👤kaezarrex
Source:stackexchange.com