def get_view_for_model(request, model="", id=-1): # Map for model to page names model_map = {"review": Review, "professor": Professor, "school": School, } if model not in model_map: json_error("Unknown/unsupported model specified") # This one is sort of hacked in, it redirects to your reports list if model == "resolve_report": url = "/browse/reports" else: url = reverse(model, args=[id]) return HttpResponse(json.dumps({"url": url}))
def model_values(request, model_name, id): """ Gets values for a model instance. """ try: # Create modelmap model = get_model_from_string(model_name) except ValueError: return HttpResponse(json.dumps({"error": {"error": "Unknown model requested."}})) instance = model.objects.filter(id=id)[0] if not instance: return json_error("Unknown id provided.") return HttpResponse(instance.to_json())