#4787: Updating queryset on a ModelChoiceField
----------------------------------------+-----------------------------------
Reporter:  fero <[EMAIL PROTECTED]>  |       Owner:  adrian                   
  Status:  new                          |   Component:  django.newforms         
 
 Version:  SVN                          |    Keywords:  ModelChoiceField 
Queryset
   Stage:  Unreviewed                   |   Has_patch:  1                       
 
----------------------------------------+-----------------------------------
 {{{
 The problem is that updating the queryset for a forms.ModelChoiceField in
 a form doesn't change widget choices because they are set at
 ModelChoiceField __init__ time.
 This code works (in __init__ of my form):
 MyForm.base_fields['activity'].queryset =
 Activity.objects.filter(user__id=2)
 MyForm.base_fields['activity'].widget.choices =
 MyForm.base_fields['activity'].choices
 
 So I propose the following patch in newforms/models.py
 (I've never used "property" before)
 
 class ModelChoiceField(ChoiceField):
 
     .....
 
     def _set_queryset(self, value):
         self._queryset = value
         self.widget.choices = self.choices
     def _get_queryset(self):
         return self._queryset
 
     queryset = property(_get_queryset, _set_queryset)
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/4787>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" 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-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to