On Jul 11, 2009, at 6:23 PM, adelaide_mike wrote:
> > Thanks Alex. > > A simpler way out would be if the agent field, which is a foreign key > pick list, could be caused to show only those values I determine > dynamically. > > Is this possible in a ModelForm? > > Mke If I understand correctly, what would help you is to add that 'agent' field to the exclude tuple of your model form and add another ChoiceField, setting its 'choices' dynamically in the __init__ of your ModelForm. Something vaguely like this: class ListingForm(forms.ModelForm): agent_id = forms.ChoiceField() def __init__(self, *args, **kwargs): realtor = kwargs.pop('realtor') super(ListingForm, self).__init__(*args, **kwargs) agent_choices = [('', '--SELECT AGENT--')] + [(str(x.id), x.name) for x in realtor.agent_set.all()] self.fields['agent_id'].choices = agent_choices class Meta: model = Listing exclude = ('agent',) --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---