[Answered ]-Creating a drop-down menu of Member IDs

2👍

Member.objects.values(‘member_id’) gives you list of dictionaries with values structured as {‘member_id’: value}.

If you just want the ids, you can make Member.objects.values_list(‘member_id’, flat=True) which will just give you list of member ids.

Anyways you try to use ModelChoiceField which expects a queryset of Model instances and you try to pass to it a list of slugs.

What you want to do is
ModelChoiceField(queryset=Member.objects.all(), to_field_name=’member_id’)
Normally ModelChoiceFields gets id as option, but you can override it with to_field_name :

https://github.com/django/django/blob/master/django/forms/models.py#L1129-L1144

👤snejy

Leave a comment