From 0323efb4f49ca1c3996b56288a2382ee9e549ebc Mon Sep 17 00:00:00 2001
From: csae8092
Date: Sun, 13 Oct 2024 08:58:11 +0200
Subject: [PATCH 1/2] after editing a relation in an enttiy detail view, only
show the last ten edited relations
---
apis_core/apis_relations/forms2.py | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/apis_core/apis_relations/forms2.py b/apis_core/apis_relations/forms2.py
index 540c393..c81e7ba 100644
--- a/apis_core/apis_relations/forms2.py
+++ b/apis_core/apis_relations/forms2.py
@@ -108,17 +108,11 @@ def get_html_table(self, entity_type, request, site_instance, form_match):
if form_match.group(1) == form_match.group(2):
dic_a = {"related_" + entity_type.lower() + "a": site_instance}
dic_b = {"related_" + entity_type.lower() + "b": site_instance}
- if "apis_highlighter" in settings.INSTALLED_APPS:
- objects = self.relation_form.objects.filter_ann_proj(
- request=request
- ).filter(Q(**dic_a) | Q(**dic_b))
- else:
- objects = self.relation_form.objects.filter(Q(**dic_a) | Q(**dic_b))
-
+ objects = self.relation_form.objects.filter(Q(**dic_a) | Q(**dic_b)).order_by("-updated")[:10]
table_html = table(data=objects, prefix=prefix)
else:
tab_query = {"related_" + entity_type.lower(): site_instance}
- ttab = self.relation_form.objects.filter(**tab_query)
+ ttab = self.relation_form.objects.filter(**tab_query).order_by("-updated")[:10]
table_html = table(data=ttab, prefix=prefix)
return table_html
From c7cd7f1f3bbe5359e6beeb611bbbf3b843a908df Mon Sep 17 00:00:00 2001
From: csae8092
Date: Sun, 13 Oct 2024 09:34:06 +0200
Subject: [PATCH 2/2] link to filtered relation view
---
apis_core/apis_entities/detail_views.py | 9 +++++++++
.../detail_views/entity_detail_generic.html | 4 ++--
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/apis_core/apis_entities/detail_views.py b/apis_core/apis_entities/detail_views.py
index 11a959e..104047c 100644
--- a/apis_core/apis_entities/detail_views.py
+++ b/apis_core/apis_entities/detail_views.py
@@ -37,6 +37,13 @@ def get(self, request, *args, **kwargs):
table = get_generic_relations_table(
relation_class=rel, entity_instance=instance, detail=True
)
+ print(match, entity)
+ if match[0] == entity:
+ link_to_relations = f"{rel.get_listview_url()}?source={pk}"
+ rel_type = match[1]
+ else:
+ link_to_relations = f"{rel.get_listview_url()}?target={pk}"
+ rel_type = match[0]
if match[0] == match[1]:
title_card = entity.title()
dict_1 = {"related_" + entity.lower() + "a": instance}
@@ -69,6 +76,8 @@ def get(self, request, *args, **kwargs):
tb_object,
"".join([x.title() for x in match]),
tb_object_open,
+ link_to_relations,
+ rel_type
)
)
object_lod = Uri.objects.filter(entity=instance)
diff --git a/apis_core/apis_entities/templates/apis_entities/detail_views/entity_detail_generic.html b/apis_core/apis_entities/templates/apis_entities/detail_views/entity_detail_generic.html
index 0431b83..e68bafb 100644
--- a/apis_core/apis_entities/templates/apis_entities/detail_views/entity_detail_generic.html
+++ b/apis_core/apis_entities/templates/apis_entities/detail_views/entity_detail_generic.html
@@ -207,8 +207,8 @@ Beziehungen
{% block relations %}
{% for obj in right_card %}
{% if obj.1.data|length > 0 %}
- {{ obj.0 }}
-
+
+
{% render_table obj.1 %}