22 lines
827 B
Python
22 lines
827 B
Python
# plants/views/dashboard.py
|
|
from datetime import date
|
|
from django.shortcuts import render
|
|
from plants.models import Plant, Location
|
|
|
|
|
|
def dashboard(request):
|
|
today = date.today()
|
|
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 [])]
|
|
latest_plants = Plant.objects.select_related('species', 'location').prefetch_related('photos').order_by('-pk')[:6]
|
|
location_count = Location.objects.count()
|
|
|
|
return render(request, 'plants/dashboard.html', {
|
|
'total_plants': len(all_plants),
|
|
'blooming_now': blooming_now,
|
|
'blooming_now_count': len(blooming_now),
|
|
'today': today,
|
|
'latest_plants': latest_plants,
|
|
'location_count': location_count,
|
|
'active_tab': 'home',
|
|
})
|