views.py
def show(request, year, month):
clndr = calendar.monthcalendar(int(year), int(month))
event = Event.objects.filter(date__year=int(year), date__month=int(month))
# Next month
if int(month) == 12:
next_year = int(year) + 1
next_month = 1
else:
next_year = int(year)
next_month = int(month) + 1
# Previous month
if int(month) == 1:
prev_year = int(year) - 1
prev_month = 12
else:
prev_year = int(year)
prev_month = int(month) - 1
return render(request, '_calendar/index.html',
{'calendar': clndr,
'event': event,
'next_year': next_year,
'next_month': next_month,
'prev_year': prev_year,
'prev_month': prev_month})
{% extends "base.html" %}
{% block content %}
<a href="{% url show prev_year prev_month %}">Previous month</a>
<a href="{% url show next_year next_month %}">Next month</a>
<table border='1'>
{% for week in calendar%}
<tr>
{% for day in week %}
{% if day = 0 %}
<td></td>
{% else %}
<td class="td">{{ day }}
{% for row in event %}
{% if row.date.day = day %}
<br>{{ row.title }} {{ row.time }}
{% endif %}
{% endfor %}
</td>
{% endif %}
{% endfor %}
</tr>
{% endfor %}
</table>
{% endblock %}
from django.db import models
TITLE_CHOICES = (
('None', 'none'),
('Day', 'day'),
('Week', 'week'),
('Month', 'month'),
('Year', 'year'),
)
class Event(models.Model):
user = models.CharField(max_length=30)
title = models.CharField(max_length=60)
date = models.DateField(unique=True)
time = models.TimeField(blank=True)
iteration = models.CharField(max_length=5, choices=TITLE_CHOICES)