Mario Gonzalez said the following:
> That's what I want to solve, give the opportunity to the programmer
> to change the queryset easily when a form_for_model is needed but you
> don't need the default queryset.
I understand what you want, and you can do it with a formfield_callback!
You do /not/ need some new, custom addition to form_for_model for this
very, very narrow use-case.
###############
def my_callback(f, **kwargs):
if f.name == "districts":
kwargs['queryset'] = District.objects.filter(id__in=[1, 2, 3])
return f.formfield(**kwargs)
MyForm = forms.form_for_model(Region, formfield_callback=my_callback)
form = MyForm()
###############
And voila, now you have your queryset replaced. And this can be expanded
quite easily to support multiple m2m fields or foreignkeys or whatever
else you need to change, unlike your limited solution.
So as you can see, the ability to replace the queryset already exists,
and in a much better form :)
--
Collin Grady
The meta-Turing test counts a thing as intelligent if it seeks to
devise and apply Turing tests to objects of its own creation.
-- Lew Mammel, Jr.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---