app/django/contrib/databrowse/views.py
author Pawel Solyga <Pawel.Solyga@gmail.com>
Tue, 16 Sep 2008 15:56:15 +0000
changeset 150 715b07485c48
parent 54 03e267d67478
child 323 ff1a9aa48cfd
permissions -rw-r--r--
Changed ZIPFILE variable to DJANGO_ZIPFILE in make_release.sh script and added 'cd $APP_FOLDER' before we zip django.

from django.db.models import FieldDoesNotExist, DateTimeField
from django.http import Http404
from django.shortcuts import render_to_response
from django.contrib.databrowse.datastructures import EasyModel, EasyChoice

###########
# CHOICES #
###########

def choice_list(request, app_label, module_name, field_name, models):
    m, f = lookup_field(app_label, module_name, field_name, models)
    return render_to_response('databrowse/choice_list.html', {'model': m, 'field': f})

def choice_detail(request, app_label, module_name, field_name, field_val, models):
    m, f = lookup_field(app_label, module_name, field_name, models)
    try:
        label = dict(f.field.choices)[field_val]
    except KeyError:
        raise Http404('Invalid choice value given')
    obj_list = m.objects(**{f.field.name: field_val})
    return render_to_response('databrowse/choice_detail.html', {'model': m, 'field': f, 'value': label, 'object_list': obj_list})