2👍
Maybe use F class
from django.db.models import F
total_no_modules = plants.aggregate(sum=Sum(F('nominal_power')*1000-F('module_nominal_power')))
0👍
@Marcin you are correct but I was looking for this:
def home(request):
plants = Plant.objects.filter(user=request.user)
total_power = plants.aggregate(sum=Sum('nominal_power'))
total_no_modules = 0
for plant in plants
total_no_modules = total_no_modules + plant.no_modules
template = 'data/home.html'
context = {'plants':plants,
'total_power':total_power,
'total_no_modules':total_no_modules}
return render(request, template, context)
- [Answered ]-Django HTML for loop not showing corresponding values
- [Answered ]-Django-filter: add "All" filter option for AllValuesFilter with LinkWidget
- [Answered ]-Django Rest Framework: How to get value of the ForeignKey
Source:stackexchange.com