>
> 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',)