From dff1c8874876d140f57131ae694eb9af300fb1a6 Mon Sep 17 00:00:00 2001 From: Stephan Kerkman Date: Thu, 28 May 2026 21:59:04 +0200 Subject: [PATCH] feat: show plant card button on detail page when card photos exist Co-Authored-By: Claude Sonnet 4.6 --- plants/templates/plants/plant_detail.html | 4 ++++ plants/tests/test_views.py | 11 +++++++++++ plants/views/plants.py | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/plants/templates/plants/plant_detail.html b/plants/templates/plants/plant_detail.html index 21ceb04..0f2e3e1 100644 --- a/plants/templates/plants/plant_detail.html +++ b/plants/templates/plants/plant_detail.html @@ -77,6 +77,10 @@ {% include "plants/partials/photo_gallery.html" %} +{% if plant.card_photos.exists %} +🪧 View plant card +{% endif %} + Delete plant {% endblock %} diff --git a/plants/tests/test_views.py b/plants/tests/test_views.py index b074f47..1e87813 100644 --- a/plants/tests/test_views.py +++ b/plants/tests/test_views.py @@ -88,6 +88,17 @@ class TestPlantDetail: assert resp.context['plant'] == plant assert resp.context['pruning_status'] == 'no_schedule' + def test_card_button_shown_when_card_photos_exist(self, client): + plant = Plant.objects.create(name='Fern') + PlantCardPhoto.objects.create(plant=plant, image='plants/cards/card.jpg') + resp = client.get(reverse('plant_detail', args=[plant.pk])) + assert 'View plant card' in resp.content.decode() + + def test_card_button_hidden_when_no_card_photos(self, client): + plant = Plant.objects.create(name='Fern') + resp = client.get(reverse('plant_detail', args=[plant.pk])) + assert 'View plant card' not in resp.content.decode() + @pytest.mark.django_db class TestLogPruning: diff --git a/plants/views/plants.py b/plants/views/plants.py index 2e46daa..c5d0131 100644 --- a/plants/views/plants.py +++ b/plants/views/plants.py @@ -29,7 +29,7 @@ def plant_list(request): def plant_detail(request, pk): plant = get_object_or_404( - Plant.objects.select_related('species', 'location').prefetch_related('pruning_logs', 'photos'), + Plant.objects.select_related('species', 'location').prefetch_related('pruning_logs', 'photos', 'card_photos'), pk=pk, ) today = date.today()