feat: show 6 most recently added plants on dashboard with images
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
d573dfbbda
commit
ba69a1b74a
2 changed files with 25 additions and 0 deletions
|
|
@ -42,6 +42,29 @@
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if latest_plants %}
|
||||||
|
<div class="card mb-3">
|
||||||
|
<div class="card-header fw-semibold">🌿 Recently added</div>
|
||||||
|
<div class="list-group list-group-flush">
|
||||||
|
{% for plant in latest_plants %}
|
||||||
|
<a href="{% url 'plant_detail' plant.pk %}" class="list-group-item list-group-item-action d-flex align-items-center gap-3 py-2 text-decoration-none">
|
||||||
|
{% if plant.species and plant.species.api_image_url %}
|
||||||
|
<img src="{{ plant.species.api_image_url }}" width="48" height="48" class="rounded" style="object-fit:cover;flex-shrink:0;">
|
||||||
|
{% elif plant.thumbnail_url %}
|
||||||
|
<img src="{{ plant.thumbnail_url }}" width="48" height="48" class="rounded" style="object-fit:cover;flex-shrink:0;">
|
||||||
|
{% else %}
|
||||||
|
<div style="width:48px;height:48px;background:#d8f3dc;border-radius:.375rem;flex-shrink:0;display:flex;align-items:center;justify-content:center;">🌿</div>
|
||||||
|
{% endif %}
|
||||||
|
<div>
|
||||||
|
<div class="fw-semibold" style="color:#1b4332;">{{ plant.name }}</div>
|
||||||
|
<small class="text-muted">{{ plant.location }}</small>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<div class="d-grid">
|
<div class="d-grid">
|
||||||
<a href="{% url 'plant_add' %}" class="btn btn-success">+ Add a plant</a>
|
<a href="{% url 'plant_add' %}" class="btn btn-success">+ Add a plant</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,12 @@ def dashboard(request):
|
||||||
today = date.today()
|
today = date.today()
|
||||||
all_plants = list(Plant.objects.select_related('species').all())
|
all_plants = list(Plant.objects.select_related('species').all())
|
||||||
blooming_now = [p for p in all_plants if today.month in (p.bloom_months or [])]
|
blooming_now = [p for p in all_plants if today.month in (p.bloom_months or [])]
|
||||||
|
latest_plants = Plant.objects.select_related('species', 'location').prefetch_related('photos').order_by('-pk')[:6]
|
||||||
|
|
||||||
return render(request, 'plants/dashboard.html', {
|
return render(request, 'plants/dashboard.html', {
|
||||||
'total_plants': len(all_plants),
|
'total_plants': len(all_plants),
|
||||||
'blooming_now': blooming_now,
|
'blooming_now': blooming_now,
|
||||||
'blooming_now_count': len(blooming_now),
|
'blooming_now_count': len(blooming_now),
|
||||||
'today': today,
|
'today': today,
|
||||||
|
'latest_plants': latest_plants,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue