cmsmanage/tasks/forms.py

26 lines
691 B
Python
Raw Normal View History

from datetime import datetime
from django import forms
from markdownx.widgets import MarkdownxWidget
from .models import Event
2022-01-24 23:37:04 -05:00
class EventForm(forms.ModelForm):
class Meta:
model = Event
2022-01-24 23:37:04 -05:00
fields = ["date", "user", "notes"]
widgets = {
2022-01-24 23:37:04 -05:00
"notes": MarkdownxWidget(attrs={"rows": 2}),
}
def __init__(self, *args, **kwargs):
2022-01-24 23:37:04 -05:00
user = kwargs.pop("user")
super().__init__(*args, **kwargs)
2022-01-24 23:37:04 -05:00
self.fields["date"].initial = datetime.now()
self.fields["user"].initial = user
if not user.is_staff:
2022-01-24 23:37:04 -05:00
print(list(self.fields["user"].choices))
self.fields["user"].choices = [(user.id, user)]