I am using fullcalendar jquery
library to display a calendar in my django
blog application page.I have some Post
s created by a logged in <
You need to give fullcalendar "events" data, that could be number of posts and that will be rendered as events. According to the docs it could be in different formats, like js array. You just need to pass that data into template. Template then could look like this:
<script>
...
$('#calendar').fullCalendar({
events: {{ posts_counts|safe }}
});
...
</script>
Where posts_counts
is array of dicts in format that fullcalendar supports, look here.
View could look like this. It's rough example, just to show how it could be done:
def calendar(request):
posts_counts = []
for i in (1, 31):
posts_counts.append({'title': len(Post.objects.filter(month='april', day=i)),
'start': '2012-04-%d' % i,
'end': '2012-04-%d' % i})
return render(request, 'calendar_template.html',
{'posts_counts': simplejson.dumps(posts_counts)})
Then fullcalendar on your page should be initialized with number of posts as events. Probably you could then customize calendar look, disable events drag&drop etc.
Your solution that finds number of posts will generate a lot of SQL queries and it'd be much better to think of a better solution.