Skip to content

Instantly share code, notes, and snippets.

View alex's full-sized avatar

Alex Gaynor alex

View GitHub Profile
from django.shortcuts import get_object_or_404, render_to_response
from django.template import RequestContext
from myapp.models import Note
def note_detail(request, slug):
note = get_object_or_404(Note, slug=slug)
editable = request.user.is_authenticated and request.user.id == note.author.id
return render_to_response('myapp/note_detail.html', {
import operator
from django.db.models import Q
from django.shortcuts import _get_queryset
def search(klass, search_fields, search_string):
"""
Perform a quick and dirty model "search", similar to how the admin's
`search_fields` works (see http://tinyurl.com/66xz2n)::