for Miles, owner, All I need is subset of data. I have tried everything in code below, passing choices , queryset, changing to choicefield etc. It just ignores everything and gets data from __unicode_ function for the foreign key table - all rows. ( I am learning Python through Django, so may be I am making some python newbie mistake here)
Miles and Owner are defined as foreign_key to respective tables. class NewCaseForm(ModelForm): def __init__(self, *args, **kwargs): super(NewCaseForm, self).__init__(*args, **kwargs) my_group_dict =args[0] my_group = my_group_dict['my_group'] # self.fields['Miles'].choices = [(miles.id, miles.miles_name) for miles in Miles.objects.filter(group__exact=my_group)] # self.fields['Miles'].queryset = [(miles.id, miles.miles_name) for miles in Miles.objects.filter(group__exact=my_group)] self.fields['Owner'].choices = [(p.id, p.last_name) for p in Participant.objects.filter(group__exact=my_group)] print self.fields['Miles'].choices Miles =forms.ChoiceField(widget=forms.Select(attrs=attrs_dict)) Owner =forms.ChoiceField(choices=(), widget=forms.Select(attrs=attrs_dict),required=False) class Meta: model= Case exclude = ('group','create_date_time','create_user_id') On Apr 9, 1:07 pm, "James Bennett" <[EMAIL PROTECTED]> wrote: > On Wed, Apr 9, 2008 at 2:56 PM, ydjango <[EMAIL PROTECTED]> wrote: > > Not for model form, if a ChoiceField is based on foreign Key. It is > > getting values from the referenced table using the __unicode__ method > > in that table and ignoring the choices field passed to it. > > Not in this case; the moment you change any aspect of the definition > of a field in a ModelForm, you're 100% on your own for that field. > This means that if you change any aspect of the definition of a > choice-based field in a ModelForm, you're on the hook for all its > other required attributes, including choices. > > -- > "Bureaucrat Conrad, you are technically correct -- the best kind of correct." --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---