2020-12-24 15:30:45 -05:00
|
|
|
from datetime import datetime
|
|
|
|
|
2020-12-03 12:31:39 -05:00
|
|
|
from django import forms
|
|
|
|
|
|
|
|
from .models import Event
|
|
|
|
|
|
|
|
class EventForm(forms.ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = Event
|
|
|
|
fields = ['date', 'user', 'notes']
|
2020-12-24 15:30:45 -05:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
user = kwargs.pop('user')
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
self.fields['date'].initial = datetime.now()
|
|
|
|
self.fields['user'].initial = user
|
2020-12-24 15:31:43 -05:00
|
|
|
if not user.is_staff:
|
|
|
|
print(list(self.fields['user'].choices))
|
|
|
|
self.fields['user'].choices = [(user.id, user)]
|