# forms.py from django import forms from .models import Message, Reply, CustomUser class MessageForm(forms.ModelForm): receivers = forms.ModelMultipleChoiceField( queryset=CustomUser.objects.filter(is_active=True), label="Receivers", widget=forms.SelectMultiple(attrs={'class': 'form-control'}) ) class Meta: model = Message fields = ['receivers', 'subject', 'body', 'attachment'] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['receivers'].label_from_instance = lambda obj: f"{obj.first_name} {obj.last_name}" class ReplyForm(forms.ModelForm): class Meta: model = Reply fields = ['body', 'attachment']