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
-~----------~----~----~----~------~----~------~--~---

Reply via email to