cmsmanage/tasks/forms.py

21 lines
557 B
Python

from datetime import datetime
from django import forms
from .models import Event
class EventForm(forms.ModelForm):
class Meta:
model = Event
fields = ['date', 'user', 'notes']
def __init__(self, *args, **kwargs):
user = kwargs.pop('user')
super().__init__(*args, **kwargs)
self.fields['date'].initial = datetime.now()
self.fields['user'].initial = user
if not user.is_staff:
print(list(self.fields['user'].choices))
self.fields['user'].choices = [(user.id, user)]