将JavaScript按钮链接到Django表单

时间:2018-12-01 13:57:38

标签: javascript django fullcalendar django-scheduler

我有一个用于显示全日历的JavaScript函数。在那里,我添加了一个自定义按钮(addEventButton)以添加新事件:

      $('#calendar').fullCalendar({
      header: {
        center: 'addEventButton',
      },
      events: '/schedule/api/occurrences?calendar_slug=calendar',
      customButtons: {
        addEventButton: {
          text: '+',
          click: function() {
            var dateStr = prompt('Enter a date in YYYY-MM-DD format');
            var date = moment(dateStr);

            if (date.isValid()) {
              $('#calendar').fullCalendar('renderEvent', {
                title: 'dynamic event',
                start: date,
                allDay: true
              });
          }
        }
        }
      });

要将这些新事件放入存储所有事件的django模型中,我制作了一个form.py:

class create_calendar_event(forms.Form):
      Title = ModelChoiceField(label='Title', queryset=Title.objects.all())
      INPUT_FORMATS = ['%Y-%m-%d %H:%M']
      start = forms.DateTimeField(input_formats=INPUT_FORMATS, 
                                  widget=forms.DateTimeInput())
      end = get_end_time(start)
      calendar = ModelChoiceField(label='Calendar', 
                                  queryset=Calendar.objects.all())

如何将这个create_calendar_event表单链接到JavaScript addEventButton?

0 个答案:

没有答案