From 405ff8cb7a835cfa91a4f485d06ce972fba6b0c5 Mon Sep 17 00:00:00 2001
From: Bill Fenner <fenner@fenron.net>
Date: Tue, 22 May 2007 19:53:28 +0000
Subject: [PATCH] Allow specifying querysets.

Given the number of kwargs that some constructors take, perhaps the
better thing would be to be able to say "this field gets these
kwargs", so we could instead pass something like
other = { 'foo': {'queryset': Foo.objects.all()}, 'bar': {'fwip': 'baz'} }.
 - Legacy-Id: 147
---
 ietf/contrib/form_decorator.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/ietf/contrib/form_decorator.py b/ietf/contrib/form_decorator.py
index af4554540..3cfae8c10 100644
--- a/ietf/contrib/form_decorator.py
+++ b/ietf/contrib/form_decorator.py
@@ -1,7 +1,7 @@
 ## formfield_callback generator
 ## http://www.djangosnippets.org/snippets/59/
 def form_decorator(fields = {}, attrs = {}, widgets = {}, 
-    labels = {}, choices = {}):
+    labels = {}, choices = {}, querysets = {}):
     
     """
     This function helps to add overrides when creating forms from models/instances.
@@ -64,6 +64,10 @@ def form_decorator(fields = {}, attrs = {}, widgets = {},
             choice_set = choices[f.name]
             if callable(choice_set) : choice_set = choice_set()
             kw["choices"] = choice_set
+
+        if f.name in querysets:
+        
+            kw["queryset"] = querysets[f.name]
             
                 
         return f.formfield(**kw)