using jquery fullcalendar in django app

前端 未结 1 1224
你的背包
你的背包 2021-02-06 19:28

I am using fullcalendar jquery library to display a calendar in my django blog application page.I have some Posts created by a logged in <

1条回答
  •  闹比i
    闹比i (楼主)
    2021-02-06 19:49

    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:

    
    

    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.

    0 讨论(0)
提交回复
热议问题