columns.py 746 B

1234567891011121314151617181920212223242526
  1. import django_tables2 as tables
  2. __all__ = (
  3. 'TenantColumn',
  4. )
  5. class TenantColumn(tables.TemplateColumn):
  6. """
  7. Include the tenant description.
  8. """
  9. template_code = """
  10. {% if record.tenant %}
  11. <a href="{{ record.tenant.get_absolute_url }}" title="{{ record.tenant.description }}">{{ record.tenant }}</a>
  12. {% elif record.vrf.tenant %}
  13. <a href="{{ record.vrf.tenant.get_absolute_url }}" title="{{ record.vrf.tenant.description }}">{{ record.vrf.tenant }}</a>*
  14. {% else %}
  15. &mdash;
  16. {% endif %}
  17. """
  18. def __init__(self, *args, **kwargs):
  19. super().__init__(template_code=self.template_code, *args, **kwargs)
  20. def value(self, value):
  21. return str(value) if value else None