Skip to main content

An extension for IPython that help to define django's models in your interactive session.

Project description

Latest PyPI version Number of PyPI downloads
author:

Martín Gaitán <gaitan@gmail.com>

homepage:

https://github.com/mgaitan/django-orm-magic

Define your django models in an IPython cell and use them on the fly. Let the magic do the boring part.

Django ORM isn’t not conceived to be used standalone. Even for a trivial case, you need configure a database, creat an app, etc. This magic handle that automatically, and then import every model to your interactive session.

Install

You can install or upgrade via pip

pip install -U django-orm-magic

or directly from the repository using the %install_ext magic command:

In[1]: %install_ext https://raw.github.com/mgaitan/django-orm-magic/master/django_orm_magic.py

Basic usage

Once it’s installed, you can load it with %load_ext django_orm_magic. Then define your models in a cell started with the cell magic %%django_orm`. For example:

In[2]: %load_ext django_orm_magic


In[3]: %%django_orm

       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)

And it’s done. Every model is synced in a sqlite database named db.sqlite in your current path and imported automatically:

In[4]: Poll.objects.all()
Out[4]: []

In[5]: from django.utils import timezone
       p = Poll(question="What's new?", pub_date=timezone.now())
       p.save()

See here for another example

Changelog

0.2 / 2013-12-11

  • Moved the code to github.

  • Packaged and registered in PyPi

0.1 / 2013-10-29

  • First public release (as a gist)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-orm-magic-0.2.tar.gz (3.4 kB view details)

Uploaded Source

File details

Details for the file django-orm-magic-0.2.tar.gz.

File metadata

File hashes

Hashes for django-orm-magic-0.2.tar.gz
Algorithm Hash digest
SHA256 9e70cbcc0559fece653bccd3a6012736177b82338fcf56a6867bd6c33871b0b7
MD5 34d30df5564a86125d42e26fc3c6713a
BLAKE2b-256 72eae2e2b83766213f864b62b9cb86e9e9f3d6bdd3762365a093d1b284f20ea6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page