ipython的一个扩展,有助于在交互式会话中定义django的模型。

django-orm-magic的Python项目详细描述


Latest PyPI versionNumber of PyPI downloads
author:Martín Gaitán <gaitan@gmail.com>
homepage:https://github.com/mgaitan/django-orm-magic
documentation:see this notebook

在ipython单元中定义django模型并动态使用它们。 让魔法来完成无聊的部分。

django orm不是独立使用的。即使是一个小例子,你也需要配置一个数据库,创建一个应用程序,等等。这个神奇的自动处理,然后将每个模型导入到你的交互会话中。

安装

您可以通过pip安装或升级

pip install -U django-orm-magic

或者直接从存储库中使用%install\u extmagic命令:

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

基本用法

一旦安装好,就可以用%load_ext django_orm_magic加载它。然后在以cell magic%%django_orm开头的单元格中定义模型。 例如:

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)

一切都结束了。每个模型都在当前路径中名为db.sqlite的sqlite数据库中同步,并自动导入:

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()

有关详细信息,请参见documentation

另一个例子见here

更改日志

0.3.1/2014-01-21

  • 修复错误#4 (现在通过pip works安装)

0.3/2013-12-14

  • 添加了%django_设置魔术
  • 添加了教程笔记本

0.2/2013-12-11

  • 将代码移到github。
  • 在PYPI中打包并注册

0.1/2013-10-29

  • 首次公开发行(作为gist

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Cassandra docker无法通过JMX连接   java以编程方式在图片模式下启用图片   java访问json数组中的json数组   swing Java 2D API:空指针异常   java Storm 2.0.0内存不足   java为什么Splitter在Spring Integration中处理集合项时直接返回集合?   java Spring启动到Postgres数据库驱动程序问题   java如何将对象围绕其中心旋转90度?   无法返回变量。“java:找不到变量”   通过BigInteger进行Java基转换   在Java中获取日期格式   java构建具有依赖关系的jar并将其绑定到tar中。gz使用maven组装   java为什么Guice在main中从UncaughtExceptionHandler抛出$ComputeException?   spring升级到Java7时有哪些陷阱   java从JTable向数组获取值   java Android在启动新活动时会杀死多个以前的活动   postgresql是否可以在批处理过程中运行java命令?   安卓使用Java代码创建文件上传请求   java一些元素神奇地没有从ArrayList中删除