class EventForm(forms.ModelForm):
"""Event form"""
client = forms.ModelChoiceField(queryset=None,empty_label="no client?")
room_calendar = forms.ModelChoiceField(queryset=None,empty_label="no room?")
class Meta:
model = Event
fields = ("client","room_calendar",
"title","description","event_type",)
labels = {
"client":"It there a client associated?(optional)",
"room_calendar":"Which room it belongs to?",
"title":"Give it a memorable title",
"description":"What it is about?",
"event_type":"Select a type of event",
}
def __init__(self, *args, **kwargs):
# Extract the user from the view
user = kwargs.pop('user')
super(EventForm, self).__init__(*args, **kwargs)
# Filter authors related to the logged-in user
self.fields['client'].queryset = Client.objects.filter(user=user)
self.fields['room_calendar'].queryset = RoomCalendarModel.objects.filter(Q(tenants__user=user)|Q(user=user))