Skip to content

Instantly share code, notes, and snippets.

@zachwill
Created August 25, 2011 07:16
Show Gist options
  • Save zachwill/1170147 to your computer and use it in GitHub Desktop.
Save zachwill/1170147 to your computer and use it in GitHub Desktop.
def category(request, model, tag):
"""
Given a lowercase model name and tag, search for all models linked to
the given tag. The model is obtained by looking through a dictionary of
available models.
"""
available_models = {'apps': App, 'data': Data, 'ideas': Idea}
try:
actual_model = available_models[model]
except KeyError:
# The model does not exist.
context = {'results': None}
else:
results = actual_model.objects.filter(tag=tag)
context = {'results': results}
return render_response(request, 'category.html', context)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment