Say I have an address
table and it has a postal_code
field -- ModelChoiceField does not allow me to use something other than PKs to validate existence
What about to_field_name
? I'm not sure if it's documented anywhere, but you can find it easily between ModelChoiceField
constructor params: https://github.com/django/django/blob/master/django/forms/models.py. It is used to filter field queryset.
For example:
articles = ModelChoiceField(queryset=Articles.objects.all(),
to_field_name='slug')