views.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from itertools import chain
  2. from django.shortcuts import render
  3. from .models import Service, Cost, Good, CostUse, GoodUse
  4. def index(request):
  5. return render(request, 'costs/index.html')
  6. def list_services(request):
  7. context = {
  8. 'services': Service.objects.all(),
  9. }
  10. return render(request, 'costs/services_list.html', context)
  11. def list_resources(request):
  12. context = {
  13. 'goods': Good.objects.all(),
  14. 'costs': Cost.objects.all(),
  15. }
  16. return render(request, 'costs/resources_list.html', context)
  17. def detail_service(request, pk):
  18. service = Service.objects.get(pk=pk)
  19. costs_uses = CostUse.objects.filter(service=service)
  20. goods_uses = GoodUse.objects.filter(service=service)
  21. context = {
  22. 'service': service,
  23. 'costs_uses': costs_uses,
  24. 'goods_uses': goods_uses,
  25. 'total_costs_price': sum(chain(
  26. (i.monthly_provision_share() for i in goods_uses),
  27. (i.cost_share() for i in costs_uses)
  28. ))
  29. }
  30. return render(request, 'costs/service_detail.html', context)