2020-12-24 15:30:45 -05:00
|
|
|
from datetime import datetime
|
|
|
|
|
2020-12-03 12:31:39 -05:00
|
|
|
from django import forms
|
2021-05-20 18:00:12 -04:00
|
|
|
from markdownx.widgets import MarkdownxWidget
|
2020-12-03 12:31:39 -05:00
|
|
|
|
|
|
|
from .models import Event
|
|
|
|
|
|
|
|
class EventForm(forms.ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = Event
|
|
|
|
fields = ['date', 'user', 'notes']
|
2021-05-20 18:00:12 -04:00
|
|
|
widgets = {
|
|
|
|
'notes': MarkdownxWidget(attrs={'rows': 2}),
|
|
|
|
}
|
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)]
|