> ## Content Index
> Fetch the complete content index at: https://multitasked.net/llms.txt
> Use this file to discover other available public pages before exploring further.

# Exporting a Schedule from a Django Application to Google Calendar
- URL: https://multitasked.net/2010/06/16/exporting-a-schedule/
- Published: 2010-06-16T06:16:00.000Z
- Updated: 2026-09-04T10:06:52.000Z
- Author: Martin De Wulf

# Disclaimer

This blog post is not very original, it is essentially a mix of two previous blog posts, one from [Andrew Turner](http://highearthorbit.com/publish-ical-to-google-calendar/?ref=multitasked.net) and one from [Derek Willis](http://blog.thescoop.org/archives/2007/07/31/django-ical-and-vobject/?ref=multitasked.net).

# And now, the real content

For my pet project, [ZoFa](http://www.zofa.biz/?ref=multitasked.net), I wanted to allow my users to publish their schedule, computed on the site, to their favourite calendar application, particulary to Google Calendar, which is the calendar application I am using myself.

To do this, there are two steps to accomplish : First,create a view generating an ical file (with extension .ics) I used the [vobject](http://vobject.skyhouseconsulting.com/?ref=multitasked.net) library to do this as showed [here](http://blog.thescoop.org/archives/2007/07/31/django-ical-and-vobject/?ref=multitasked.net).

By the way, vobject is a part of the doomed [Chandler project](http://chandlerproject.org/?ref=multitasked.net) described in [excellent book](<img src=). Highly recommended.

Having battled quite some time with this, I think that the following cod snippet could be of interest to some people. So, here is the code of my view :  

def ical(request, worker\_id):  
worker=Worker.objects.get(pk=int(worker\_id))  
cal = vobject.iCalendar()  
cal.add('method').value = 'PUBLISH' # IE/Outlook needs this  
for shift in worker.shift\_set.filter(published=True):  
vevent = cal.add('vevent')  
vevent.add('dtstart').value=shift.begin #begin and end are python datetime objects  
vevent.add('dtend').value=shift.end  
vevent.add('summary').value=shift.name  
vevent.add('uid').value=str(shift.id)  
icalstream = cal.serialize()  
response = HttpResponse(icalstream, mimetype='text/calendar')  
response\['Filename'\] = 'shifts.ics' # IE needs this  
response\['Content-Disposition'\] = 'attachment; filename=shifts.ics'  
return response  

Finally, just add the url to your urls.py :

url(r'^ical/(?P<worker\_id>\\d+)/shifts.ics$','ical',name="shifts\_ical")  

It seemed necessary for Google to pick it up to add a file name at the end of the url, but I am not sure about this.

The second step needs that your user import the url of your calendar into Google Calendar. To do this in the current interface :

1. open the "other calendars" little frame
2. click on "add" (at the bottom)
3. click "add by url" and paste the url.

Some concluding remarks :

- It can take some time before Google really requests your calendar and displays it
- The .ics file generated can also be used in Outlook, ICal or Thunderbird.
- Your url needs to be publicly available : there is no way to provide to Google Calendar a login and a password to your site.

The next step for me would be to automatize the addition to google calendar (with a nice "Add your schedule to Google Calendar" button) but I still have no idea about the feasability of this.