def add_app_type(request, app_name): all_names = [o.name for o in Application.objects.all()] types = [ t[1] for t in Application.TYPE_CHOICES ] if app_name not in all_names: Application.objects.create(name=app_name) app = Application.objects.get(name__exact=app_name) if request.POST: for type in types: if request.POST.has_key(type): app.type = type app.save() if request.POST.has_key('change'): app.type = "" app.save() has_type = bool(app.type) stuff = {'app_name': app_name, 'app_type': app.type, 'has_type': has_type, 'types': types} return render_to_response("edit_application.html", stuff)