Skip to content

Commit 405ff8c

Browse files
committed
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
1 parent 1a5402d commit 405ff8c

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

ietf/contrib/form_decorator.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## formfield_callback generator
22
## http://www.djangosnippets.org/snippets/59/
33
def form_decorator(fields = {}, attrs = {}, widgets = {},
4-
labels = {}, choices = {}):
4+
labels = {}, choices = {}, querysets = {}):
55

66
"""
77
This function helps to add overrides when creating forms from models/instances.
@@ -64,6 +64,10 @@ def formfields_callback(f, **kw):
6464
choice_set = choices[f.name]
6565
if callable(choice_set) : choice_set = choice_set()
6666
kw["choices"] = choice_set
67+
68+
if f.name in querysets:
69+
70+
kw["queryset"] = querysets[f.name]
6771

6872

6973
return f.formfield(**kw)

0 commit comments

Comments
 (0)