Browse Source

Cust. crispy_layout para render. de related_name

Nos layouts (layouts.yaml) pode-se criar layouts específicos para renderização de related_names.
Veja exemplo de MateriaLegislativaDetail que renderiza numeracao_set
pull/854/head
Leandro Roberto da Silva 8 years ago
committed by Eduardo Edson Batista Cordeiro Alves
parent
commit
0258044977
  1. 14
      sapl/crispy_layout_mixin.py

14
sapl/crispy_layout_mixin.py

@ -61,8 +61,12 @@ def get_field_display(obj, fieldname):
try: try:
field = obj._meta.get_field(fieldname) field = obj._meta.get_field(fieldname)
except: except:
value = getattr(obj, fieldname) field = getattr(obj, fieldname)
return '', str(value) if 'ManyRelatedManager' not in str(type(field))\
and 'RelatedManager' not in str(type(field))\
and 'GenericRelatedObjectManager' not in str(type(field)):
return '', str(field)
verbose_name = str(field.verbose_name)\ verbose_name = str(field.verbose_name)\
if hasattr(field, 'verbose_name') else '' if hasattr(field, 'verbose_name') else ''
if hasattr(field, 'choices') and field.choices: if hasattr(field, 'choices') and field.choices:
@ -98,7 +102,11 @@ def get_field_display(obj, fieldname):
display += '<li>%s</li>' % str(v) display += '<li>%s</li>' % str(v)
display += '</ul>' display += '</ul>'
if not verbose_name: if not verbose_name:
verbose_name = str(field.related_model._meta.verbose_name_plural) if hasattr(field, 'related_model'):
verbose_name = str(
field.related_model._meta.verbose_name_plural)
elif hasattr(field, 'model'):
verbose_name = str(field.model._meta.verbose_name_plural)
else: else:
display = str(value) display = str(value)
return verbose_name, display return verbose_name, display

Loading…
Cancel
Save