cmsmanage/tasks/forms.py

27 lines
692 B
Python

from datetime import datetime
from django import forms
from markdownx.widgets import MarkdownxWidget
from .models import Event
class EventForm(forms.ModelForm):
class Meta:
model = Event
fields = ["date", "user", "notes"]
widgets = {
"notes": MarkdownxWidget(attrs={"rows": 2}),
}
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)]