Coder Social home page Coder Social logo

techscientist / django-orm-magic Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mgaitan/django-orm-magic

0.0 1.0 0.0 159 KB

An extension for IPython that help to define and use django's models on the fly

License: BSD 3-Clause "New" or "Revised" License

Python 27.59% Jupyter Notebook 72.41%

django-orm-magic's Introduction

Django ORM Magic

Latest PyPI version

Number of PyPI downloads

author

Martín Gaitán <[email protected]>

homepage

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

documentation

see this notebook

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 conceived to be used standalone. Even for a trivial case, you need to configure a database, create 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 the documentation for further details.

See here for another example

django-orm-magic's People

Contributors

mgaitan avatar

Watchers

Subhash Ramesh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.