Skip to content
Advertisement

Django attaching events to days in a calendar?

I have built a basic calendar which generates a table with the current month (taken from the URL) using the built-in calendar.Calendar function, but I would like to attach events to the days that are generated. What would be the best way to do that?

Currently in my views:

JavaScript

And in my template I can call the weeks and days like this:

JavaScript

What I would love to do is have something like this in my views:

JavaScript

But I get this error: TypeError: ‘datetime.date’ object does not support item assignment

Is there a way I can easily convert these days to objects that support item assignment so I can attach Events to the days and add them to the calendar?

Advertisement

Answer

I got it working based off of delta32’s suggestion. I needed to create an empty Events dictionary, then append each of the weeks to the events dictionary after running through my foor loop. That leaves me with:

JavaScript

Then, in the calendar template:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement