使用FullCalendar和Python / Django将数据插入数据库

时间:2019-04-21 14:22:09

标签: python-3.x fullcalendar django-2.0

我在正在开发的Web应用程序中使用FullCalendar插入,编辑和删除事件数据时遇到问题

我希望所有内容都可以在同一屏幕上工作,也就是说,当用户在日历中选择日期时,模态似乎会插入值(标题和日期),当您单击事件时,模态就会进行编辑该事件就会出现,并有一个删除它的按钮。

到目前为止,我所能做的是:

<script>

$(document).ready(function () {

    $('#calendar').fullCalendar({
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        },
        navLinks: true,
        editable: true,
        eventLimit: true,
        selectable: true,
        selectHelper: true,
        select: function (start, end) {
            $('#cadastrar #start').val(moment(start).format('DD/MM/YYYY HH:mm:ss'));
            $('#cadastrar #end').val(moment(end).format('DD/MM/YYYY HH:mm:ss'));
            $('#cadastrar').modal('show');
        },
    });

});

<script>

模板(agenda / agenda.html)中,我做到了,它对应于计划和在日历中选择任何日期时打开的模式。


<section class="content">
     <div id='calendar'></div>

    <div class="modal fade" id="cadastrar" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
         data-backdrop="static">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title text-center">Cadastrar Evento</h4>
                </div>
                <div class="modal-body">
                    <form role="form" action="" method="post">
                        {% csrf_token %}
                          <div class="form-group">
                              {{form.event_name}}
                          </div>
                          <div class="form-group">
                              {{form.start_date}}
                          </div>
                          <div class="form-group">
                              {{form.end_date}}
                          </div>
                          <div class="form-group">
                              {{form.event_type}}
                          </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</section>

models.py 中创建了以下

class Event(models.Model):
    event_name = models.CharField(max_length=255, null=True, blank=True)
    start_date = models.DateTimeField(null=True, blank=True)
    end_date = models.DateTimeField(null=True, blank=True)
    event_type = models.CharField(max_length=10, null=True, blank=True)

    def __str__(self):
        return self.event_name

观看次数


class AddEventView(CustomCreateView):
    form_class = EventForm
    template_name = "agenda/agenda.html"
    permission_codename = 'add_event'

    def get_context_data(self, **kwargs):
        context = super(AddEventView, self).get_context_data(**kwargs)
        return context

    def get(self, request, *args, **kwargs):
        return super(AddEventView, self).get(request, *args, **kwargs)

    def post(self, request, *args, **kwargs):
        self.object = None
        form_class = self.get_form_class()
        form = self.get_form(form_class)

        if form.is_valid():
            self.object = form.save(commit=False)
            self.object.save()
            return self.form_valid(form)

        return self.form_invalid(form)

class EventsListView(CustomListView):
    template_name = 'agenda/agenda.html'
    model = Event
    context_object_name = 'all_eventos'
    permission_codename = 'view_eventos'

    def get_context_data(self, **kwargs):
        context = super(EventosListView, self).get_context_data(**kwargs)
        return context


class EditEventView(CustomUpdateView):
    form_class = EventForm
    model = Event
    template_name = "agenda/agenda.html"
    permission_codename = 'change_event'

    def get_success_message(self, cleaned_data):

    def get_context_data(self, **kwargs):
        context = super(EditEventView, self).get_context_data(**kwargs)
        return context

    def post(self, request, *args, **kwargs):
        self.object = self.get_object()
        form_class = self.get_form_class()
        form = form_class(request.POST, instance=self.object)

        if form.is_valid():
            self.object = form.save()
            return self.form_valid(form)

        return self.form_invalid(form)

网址

   url(r'agenda/add/$',
        views.AddEventView.as_view(), name='addeventview'),

    url(r'agenda/$',
        views.EventsListView.as_view(), name='listeventsview'),

    url(r'agenda/edit/(?P<pk>[0-9]+)/$',
        views.EditEventView.as_view(), name='editeventview'),

如何调用模式事件,以便我可以注册,编辑和删除事件?到目前为止,模式已打开,但没有任何信息出现。问题当然是在视图中,但是如何在同一页面上以相同的模式创建,编辑和删除呢?

0 个答案:

没有答案