Re: dynamically filling ChoiceField
Here is how you can modify the form at runtime. You can write a constructor. In this example, I need the request for validation. {{{ class TestForm(forms.ModelForm): class Meta: model=Filter_Test def __init__(self, request, *args, **kwargs): super(TestForm, self).__init__(*args, **kwargs) self.request=request ... }}} You can set choices for fields after the super call. Example: self.fields['myfield'].choices=choices Calvin Dodge schrieb: > I've been tearing out what little hair I have left trying to figure > this out. > > How do I dynamically fill a ChoiceField by filtering on a value known > to the URLView? Every "dynamic fill" example I've found assumes the > form knows it all - I haven't seen anything which shows me how to pass > that value from the view to the form. > > -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: dynamically filling ChoiceField
On Jun 22, 8:08 pm, "Rishabh Manocha" <[EMAIL PROTECTED]> wrote: > Some more details would be good, but off the top of my head, something like > this might work: > > def my_view(request): >form = MyForm() >form.fields['mychoice'].choices = ((1,'ABC'),(2,'XYZ')) Thanks - that's exactly what I needed. Calvin Dodge --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: dynamically filling ChoiceField
Some more details would be good, but off the top of my head, something like this might work: def my_view(request): form = MyForm() form.fields['mychoice'].choices = ((1,'ABC'),(2,'XYZ')) I havent' been able to test this out, so make sure you do before you using it. You can of-course do any amount of pre-processing before you apply that tuple. Best, Rishabh On Mon, Jun 23, 2008 at 8:25 AM, Calvin Dodge <[EMAIL PROTECTED]> wrote: > > I've been tearing out what little hair I have left trying to figure > this out. > > How do I dynamically fill a ChoiceField by filtering on a value known > to the URLView? Every "dynamic fill" example I've found assumes the > form knows it all - I haven't seen anything which shows me how to pass > that value from the view to the form. > > Help? Please? > > Calvin Dodge > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
dynamically filling ChoiceField
I've been tearing out what little hair I have left trying to figure this out. How do I dynamically fill a ChoiceField by filtering on a value known to the URLView? Every "dynamic fill" example I've found assumes the form knows it all - I haven't seen anything which shows me how to pass that value from the view to the form. Help? Please? Calvin Dodge --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---