There is really no need to pass anything to __init__ in form In view itself you can access the forms member/global variables. It is python, so not much is private. unlike java. (other way would be to create setter methods in form, if you are an OO purist)
in the View itself, I added form = NewCaseForm() form.fields['owner'].queryset = Participant.objects.filter(group__exact=my_group) and it works. If I am missing some nuance which can cause issues later on , please let me know. Ashish On Apr 9, 12:21 pm, ydjango <[EMAIL PROTECTED]> wrote: > I need to load ChoiceField in form from table and need it to be > filtered based on parameter. > > Following seemed like a good way and works for forms.form , I can > replace object.all() by objects.filter() and pass an arg to __init_ > > But it works for class ContactUs(form.Form) but NOT for > ContactUs(ModelForm). For model form I get value in choice dropdown as > "Contact_Topics Object" rather than the display_desc > > Looks like it is common need with no good documented answers. > > Any clues, > Ashish > > (ModelChoiceField does not appear to have an easy way of filter > parameterizing the query set.) > > def __init__(self, *args, **kwargs): > super(ContactUs, self).__init__(*args, **kwargs) > self.fields['topic'].choices = [(topic.topic_name, > topic.topic_display_desc) for topic in Contact_Topics.objects.all()] > > topic = forms.ChoiceField(widget=forms.Select(attrs=attrs_dict)) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" 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-users?hl=en -~----------~----~----~----~------~----~------~--~---

