Skip to content

Instantly share code, notes, and snippets.

@linuxfood
Created March 2, 2012 00:28
Show Gist options
  • Save linuxfood/1954260 to your computer and use it in GitHub Desktop.
Save linuxfood/1954260 to your computer and use it in GitHub Desktop.
Django auto-generated admin actions
def puser_setcompanyroutines():
routines = []
for c in Company.objects.all():
fn = lambda modeladmin, request, queryset: queryset.update(company=c)
# WTF, you say? Yep. That's because django actually cares about the NAME
# of the function handles you pass it in the actions list. Stupid.
fn.__name__ = "set_company_%d" % c.id
fn.short_description = "Set selected to company %s" % c.name
routines.append(fn)
return routines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment