IPython Notebook Extensions, Django ORM Magic

Here you can find some useful IPython Notebook extensions. For example, Django ORM Magic (pip install django-orm-magic) lets you construct and query a Django database as follows:

[In] 1:

%load_ext django_orm_magic

[In] 2:

from django.db import models
class Poll(models.Model):
   question = models.CharField(max_length=200)
   pub_date = models.DateTimeField('date published')
class Choice(models.Model):
   poll = models.ForeignKey(Poll)
   choice_text = models.CharField(max_length=200)
   votes = models.IntegerField(default=0)

[In] 3:


[Out] 3:


[In] 4:

from django.utils import timezone
p = Poll(question="What's new?", pub_date=timezone.now())

[In] 5:


[Out] 5:

[<Poll: Poll object>]

Note that db.sqlite was generated.

[In] 6:


[Out] 6:

db.sqlite  DjangoORM-Magic.ipynb

F & P