From 6f977e8ebbb357feb54acd4804175f42cac7f1e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Dlouh=C3=BD?= Date: Fri, 12 Apr 2024 15:35:21 +0200 Subject: [PATCH] fix and test #71 (add view don't work on Django 5.0) --- admin_tools_stats/admin.py | 7 ++++--- admin_tools_stats/tests/test_admin.py | 7 +++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/admin_tools_stats/admin.py b/admin_tools_stats/admin.py index f7129755..3671b611 100644 --- a/admin_tools_stats/admin.py +++ b/admin_tools_stats/admin.py @@ -86,9 +86,10 @@ def criteria__criteria_dynamic_mapping_preview(self, obj): class DashboardStatsForm(forms.ModelForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.fields["default_multiseries_criteria"].queryset = CriteriaToStatsM2M.objects.filter( - stats=self.instance, - ) + if self.instance.pk: + self.fields["default_multiseries_criteria"].queryset = CriteriaToStatsM2M.objects.filter( + stats=self.instance, + ) @admin.register(DashboardStats) diff --git a/admin_tools_stats/tests/test_admin.py b/admin_tools_stats/tests/test_admin.py index ad260b14..de432f22 100644 --- a/admin_tools_stats/tests/test_admin.py +++ b/admin_tools_stats/tests/test_admin.py @@ -98,6 +98,13 @@ def test_admin_tools_stats_dashboardstatscriteria(self): response = self.client.get("/admin/admin_tools_stats/dashboardstatscriteria/") self.assertEqual(response.status_code, 200) + def test_add_view(self): + url = reverse("admin:admin_tools_stats_dashboardstats_add") + response = self.client.get(url) + self.assertEqual(response.status_code, 200) + url = reverse("admin:admin_tools_stats_dashboardstatscriteria_add") + response = self.client.get(url) + self.assertEqual(response.status_code, 200) class AdminToolsStatsAdminCharts(BaseSuperuserAuthenticatedClient): def test_admin_dashboard_page(self):