If you are wanting to do this for an admin field, you can use formfield_for_manytomany
. In skeleton form it could look like this:
def formfield_for_manytomany(self, db_field, request=None, **kwargs):
field = super().formfield_for_manytomany(db_field, request, **kwargs)
if db_field.name in ['the_field_you_want']:
# This line answers the question.
field.label_from_instance = lambda obj: "{}".format(obj.what_you_want_to_see)
# The lines below included so folks know you can
# also modify queryset and widget in this method
field.widget = forms.CheckboxSelectMultiple() # checkboxes
field.queryset = field.queryset.filter(some_field = something)
return field #important
This came from this answer which achieves the same goal but uses a Form
class instead of formfield_for_manytomany
.