On 2015-01-17 12:01, Vijay Khemlani wrote: > I don't think there is a way in Python to do that directly > > you could have a utility method that catches the exception, for > example > > def get_fk_field(obj, fk_field): > try: > return getattr(obj, fk_field) > except AttributeError: > return None
I'm pretty sure that getattr() takes an optional 3rd field for the default, so you could use def __str__(self): return _(u'#{0}, {1}, {2}').format( self.pk, getattr(self.lead, "customer_name", None), getattr(self.lead, "customer_phone", None), ) -tkc -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/20150117201557.013e20c8%40bigbox.christie.dr. For more options, visit https://groups.google.com/d/optout.