How to add calendar events with Django-Bootstrap-C

2020-06-23 09:58发布

问题:

Django-Bootstrap-Calendar (https://github.com/sandlbn/django-bootstrap-calendar) is a Django implementation of this calendar application: http://bootstrap-calendar.azurewebsites.net/

However, I can't figure out how to add events to the calendar via Django. The "non-Django" bootstrap calendar is rather simple, you just add events to the JSON file that gets loaded.

Has anyone here added events to Django-Bootstrap-Calendar before? I emailed the author of the project, however, he never responded to me.

The closest post I found to my question is here: Getting a bootstrap-calendar component to work with Django However, the author figured out how to add entries to the non-Django calendar only.

Edit: I figured out how to add events via the Admin panel. In models.py, you simply add:

###Admin
class CalendarEventAdmin(admin.ModelAdmin):
    list_display = ["title", "url", "css_class", "start", "end"]
    list_filler = ["title"]

admin.site.register(CalendarEvent,CalendarEventAdmin)

Then, in the admin panel you can add events (ultimately, I want non-admin users and anonymous visitors to be able to register events on the Calendar.)

However, this reveals a larger problem: the calendar doesn't display.

Edit 2: I have the calendar loading now by adding

{% load bootstrap_calendar %}
{% bootstrap_calendar_css %}
{% bootstrap_calendar_js language="template" %}
{% bootstrap_calendar_init language="template" %}
<!-- {% bootstrap_controls 'optional-css-classes' %} -->
{% bootstrap_calendar 'optional-css-classes' %} 

to my index.html file. However, the calendar doesn't display the event(s) created with the Admin Panel.

回答1:

Simply put

{% bootstrap_calendar_init language="template" %}

after

{% bootstrap_calendar 'optional-css-classes' %}