Django:无法在全日历上渲染时间更改



>我正在尝试将事件更改呈现到我的整个日历中,但是刷新页面时我的时间段不断消失。

我在调整大小或拖动事件时成功。一旦我在月视图中调整大小或删除事件更改,我的更改就会保存在我的数据库中,以便我的更改反映在下次刷新时。

问题是当我调整大小并放在日视图上时。我的时间更改会反映在我的数据库中,但是当我重新加载页面时,时间段会恢复到全天或上午 12 点 - 凌晨 1 点(取决于我的 allDay 是真的还是假的(。

<script>
    $(document).ready(function() {
        $('#calendar').fullCalendar({
            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,agendaWeek,agendaDay'
            },
            defaultView: 'month',
            weekNumbers: 'true',
            editable: true,
            selectable: true,
            eventLimit: true, // allow "more" link when too many events
            showNonCurrentDates: true,
             dayClick: function(date) {
                new_date = date.getFullYear() + '-' + date.getMonth() + '-' + date.getDate();
                var view = $('#calendar').fullCalendar('getView');
                    $('#calendar').fullCalendar('gotoDate',date);
                    $('#calendar').fullCalendar('changeView', 'agendaDay');
                },
            events: [
                {% for i in events %}
                {
                    id: "{{ i.id }}",
                    title: "{{ i.event_name}}",
                    start: '{{ i.start_date|date:"Y-m-d" }}',
                    end: '{{ i.end_date|date:"Y-m-d" }}',
                    allDay: {{ i.all_day|lower }},
                    url: '/world'
                },
                {% endfor %}
            ],
                eventClick: function(event, element) {
                    event.title = "CLICKED!";
                    $('#calendar').fullCalendar('updateEvent', event);},

                eventDrop: function(event, element){
                    alert("Event is now " + event.start + " " + event.end)
                    var url = 'update_event';
                    var event_start = event.start;
                    var event_end = event.end;

                    var js_timestamp_start = event_start.getTime() / 1000;
                    if (event_end != null) {
                      var js_timestamp_end = event_end.getTime() / 1000;
                    }

                    $.ajax({
                        url: url,
                        data: {
                        'event_id': event.id,
                        'event_title': event.title,
                        'event_start': js_timestamp_start,
                        'event_end': js_timestamp_end,
                        'event_allDay': event.allDay},
                        success: function (data) {
                          alert("Success!")  },
                        error:
                            function(xhr){
                            alert(xhr.statusText)
                            return false;}
                    });
                },
                eventResize: function(event, element){
                    alert("Event is now " + event.start + " " + event.end)
                    var url = 'update_event';
                    var event_start = event.start;
                    var event_end = event.end;

                    var js_timestamp_start = event_start.getTime() / 1000;
                    if (event_end != null) {
                      var js_timestamp_end = event_end.getTime() / 1000;
                    }

                    $.ajax({
                        url: url,
                        data: {
                        'event_id': event.id,
                        'event_title': event.title,
                        'event_start': js_timestamp_start,
                        'event_end': js_timestamp_end,
                        'event_allDay': event.allDay},
                        success: function (data) {
                          alert("Success!")  },
                        error:
                            function(xhr){
                            alert(xhr.statusText)
                            return false;}
                    });
                },

            }); // end #calendar
    })
</script>
def full_calendar(request):
    all_events = Events.objects.all()
    date_form = DateForm
    myr_form = MonthYearForm
    context = {
        "events": all_events,
        "get_event_types": get_event_types,
        "date_form" : date_form,
        "myr_form" : myr_form
    }
    return render(request, 'world/fullcalendar.html', context)

def update_event(request):
    event = None
    event_id = request.GET.get('event_id')
    event_start = request.GET.get('event_start')
    event_end = request.GET.get('event_end')
    event_title = request.GET.get('event_title')
    event_allDay = request.GET.get('event_allDay')
    event_allDay = event_allDay.capitalize()
    python_date_start = datetime.fromtimestamp(int(event_start))
    if event_end is not None:
        python_date_end = datetime.fromtimestamp(int(event_end))
    else:
        python_date_end = python_date_start
        #From what I remember here, event end is null, it's because start and 
        #end is the same
    event = Events.objects.get(id=event_id)
    event.event_name = event_title
    event.start_date = python_date_start
    event.end_date = python_date_end
    event.all_day = event_allDay
    event.save()
    context = {"event": event}
    return render(request, 'world/update_event.html', context)
因此,如果我有一个全天的活动,然后将其更改为上午 10 点至下午 5 点

,我希望我的事件在刷新时呈现为上午 10 点至下午 5 点。相反,我得到了上午12点到凌晨1点(因为我的allDay现在是假的(。

奇怪的是,我所做的更改会反映在我的数据库中。我只是不太确定为什么我的日期更改反映在完整日历上,而我的时间更改没有。

似乎我忘了在我的模板上添加时间部分。格式应该类似于下面的代码,一切都应该正常工作。'{{ i.start_date|date:"Y-m-d" }} {{ i.start_date|time:"H:i:s" }}

相关内容

  • 没有找到相关文章

最新更新