Skip to content

Instantly share code, notes, and snippets.

@eculver
Created September 30, 2013 23:13
Show Gist options
  • Save eculver/6771660 to your computer and use it in GitHub Desktop.
Save eculver/6771660 to your computer and use it in GitHub Desktop.
Example of creating M2M records w/ Django ORM
from datetime import datetime, date, timedelta
from myproject.apps.events import Location, Event
start = date.today()
end = start + timedelta(days=3)
location = Location(place='Mountain View, CA', venue='Shoreline Amphitheatre',
address='1 Amphitheatre Pkwy, Mountain View, CA 94043',
latitude=37.423172, longitude=-122.078266)
location.save()
event = Event(name='TEDxCupertino', about='about', start_date=start,
end_date=end, price=100.00, slug='tedx-cupertino', hashtag='tedx',
accent_color_code='222222',
photo_url='http://assets.tedcdn.com/images/ted_logo.gif',
is_live=True, physical_capacity=100, virtual_capacity=1000,
attendance=200)
event.save()
event.location.add(location)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment