Working Ninja
Simple Scripting in Django

I needed to create a slew of objects for a project I was working on. Lots of tedious and error prone work. But wait, I'm using a computer. Automation to the rescue!

I wrote my script by first importing what I needed from Django (User and the Appointment model for the objects I was going to be creating). Then, I wrote what needed to be created enclosed in a for loop. To run the script, I jumped into Django's shell and ran the execfile() command.

from django.contrib.auth.models import User
from app.models import Appointment

user_ids = [7, 8, 9, 10, 11, 12]

for i, user_id in enumerate(user_ids, start=1):
                               title="Test appointment.",
                               doctornotes="Sample doctors notes.")
./ shell

>>> execfile('app/scripts/')