Skip to content

Instantly share code, notes, and snippets.

@vbmendes
Created July 26, 2010 19:41
Show Gist options
  • Save vbmendes/491111 to your computer and use it in GitHub Desktop.
Save vbmendes/491111 to your computer and use it in GitHub Desktop.
class MyModelAdmin(ModelAdmin):
...
def __getattr__(self, name):
"""
Permite o uso de um atributo no admin com o nome
do atributo mais '_or_blank'. Exemplo: name_or_blank
"""
if name.endswith('_or_blank'):
try:
return getattr(self, name[:-9]) or u''
except AttributeError:
pass
return super(MyModelAdmin, self).__getattr__(name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment