Coverage for apis_core/apis_metainfo/tables.py: 0%

14 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-11-22 07:51 +0000

1import django_tables2 as tables 

2from django.db.models import F 

3 

4from apis_core.generic.tables import GenericTable 

5 

6from .models import Uri 

7 

8 

9class UriTable(GenericTable): 

10 entity = tables.TemplateColumn( 

11 "<a href='{{ record.root_object.get_absolute_url }}'>{{ record.root_object }}</a>", 

12 orderable=True, 

13 verbose_name="related Entity", 

14 ) 

15 ent_type = tables.TemplateColumn( 

16 "{{ record.root_object.self_contenttype.model }}", 

17 verbose_name="Entity Type", 

18 ) 

19 

20 class Meta(GenericTable.Meta): 

21 model = Uri 

22 fields = ["id", "uri", "entity", "ent_type"] 

23 exclude = ("desc",) 

24 

25 def order_ent_type(self, queryset, is_descending): 

26 queryset = queryset.annotate( 

27 ent_type=F("root_object__self_contenttype__model") 

28 ).order_by(("-" if is_descending else "") + "ent_type") 

29 return (queryset, True)