2018-01-14 17:55:35 -05:00
|
|
|
from django.db.models import Count
|
2017-08-17 13:20:57 -04:00
|
|
|
from django.shortcuts import render
|
|
|
|
|
2018-01-25 00:18:13 -05:00
|
|
|
from .models import Region, Attorney
|
2018-02-26 22:45:26 -05:00
|
|
|
from .forms import AttorneyForm
|
2017-08-17 13:20:57 -04:00
|
|
|
|
|
|
|
|
2017-09-03 15:59:37 -04:00
|
|
|
def index(request, id):
|
|
|
|
attorney = Attorney.objects.get(id=id)
|
2018-02-26 22:45:26 -05:00
|
|
|
edit_form = AttorneyForm(request.POST or None, request.FILES or None, instance=attorney)
|
|
|
|
if request.method == 'POST' and edit_form.is_valid():
|
|
|
|
edit_form.save()
|
|
|
|
return render(request, 'attorney.html', {'attorney': attorney, 'editForm': edit_form})
|
2018-01-14 17:55:35 -05:00
|
|
|
|
|
|
|
|
|
|
|
def all(request):
|
2018-01-25 00:18:13 -05:00
|
|
|
region = Region.objects.all().order_by('name')
|
|
|
|
attorneys = Attorney.objects.all().annotate(Count('region'))
|
2018-01-25 00:52:57 -05:00
|
|
|
other = Attorney.objects.filter(region=None).count() > 0
|
|
|
|
return render(request, 'all.html', {'region': region, 'attorneys': attorneys, 'other': other})
|