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
This commit is contained in:
parent
1a5402da0b
commit
405ff8cb7a
|
@ -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.
|
||||
|
@ -65,6 +65,10 @@ def form_decorator(fields = {}, attrs = {}, widgets = {},
|
|||
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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue