equal
deleted
inserted
replaced
|
1 from django.db.models import FieldDoesNotExist, DateTimeField |
|
2 from django.http import Http404 |
|
3 from django.shortcuts import render_to_response |
|
4 from django.contrib.databrowse.datastructures import EasyModel, EasyChoice |
|
5 |
|
6 ########### |
|
7 # CHOICES # |
|
8 ########### |
|
9 |
|
10 def choice_list(request, app_label, module_name, field_name, models): |
|
11 m, f = lookup_field(app_label, module_name, field_name, models) |
|
12 return render_to_response('databrowse/choice_list.html', {'model': m, 'field': f}) |
|
13 |
|
14 def choice_detail(request, app_label, module_name, field_name, field_val, models): |
|
15 m, f = lookup_field(app_label, module_name, field_name, models) |
|
16 try: |
|
17 label = dict(f.field.choices)[field_val] |
|
18 except KeyError: |
|
19 raise Http404('Invalid choice value given') |
|
20 obj_list = m.objects(**{f.field.name: field_val}) |
|
21 return render_to_response('databrowse/choice_detail.html', {'model': m, 'field': f, 'value': label, 'object_list': obj_list}) |