Skip to content

Instantly share code, notes, and snippets.

@h4
Created March 21, 2012 20:15
Show Gist options
  • Save h4/2152399 to your computer and use it in GitHub Desktop.
Save h4/2152399 to your computer and use it in GitHub Desktop.
Построение персонала
def contacts(request):
persons = PersonToPosition.objects.all()
departments = {}
for person in persons:
department_id = person.position.department.id
if (department_id not in departments):
departments[department_id] = {
'title': person.position.department.title,
'id': department_id,
'persons': [],
'subdepartments': {}
}
if (person.education_department):
education_department_id = person.education_department.id
if(education_department_id not in departments[department_id]['subdepartments']):
departments[department_id]['subdepartments'][education_department_id] = {
'title': person.education_department.title,
'id': education_department_id,
'persons': []
}
departments[department_id]['subdepartments'][education_department_id]['persons'].append(person)
else:
departments[department_id]['persons'].append(person)
return render_to_response('contacts.html', {
'departments': departments
},
RequestContext(request))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment