views.py 995 B

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