You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
735 B
24 lines
735 B
# 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']
|