zoukankan      html  css  js  c++  java
  • djangostandalone 0.4

    django-standalone 0.4 : Python Package Index

    django-standalone 0.4

    use the Django ORM with standalone scripts

    Downloads ↓

    -*- markdown -*-
    
    Simple Standalone Scripts Using the Django ORM
    =====================================================
    
    This little library is all about easing the pain of using
    the Django ORM for simple tools that just happen to be in need
    of some easy to use ORM for object persistence.
    
    The best way of course is to set up a full Django project and
    just use a settings.py file and using the DJANGO_SETINGS_MODULE
    environment variable. But when you just want to do little tools
    that just need some sqlite3 database to store some of their
    data and don't want to go for a full Django project, that is
    where this little library comes into play.
    
    It consists of just two modules so far:
    
    standalone.conf handles all the configuration needs, setting up
    
    standalone.models carries a base class for your models that
    automatically tells Python that all models created actually
    reside in the standalone Django app, even though they are
    in a different file, outside the app's namespace.
    
    As a warning: this might be seen as voodoo, bad magic or just
    a plain stupid idea by some people. And the official way
    to do it might be a much better idea for you. I myself just
    happen to like to have the ability to easily create standalone
    executable scripts that don't rely on some predefined project
    structure.
    
    how to get it
    ---------------
    
    The easiest way to get django-standalone is to use easy_install
    or pip:
    
    sudo easy_install django-standalone
    
    or
    
    sudo pip install django-standalone
    
    Or you can clone this repository and run the included setup.py
    
    To run the included test cases, just run the following:
    
    pythons setup.py test
    
    using in your scripts:
    ------------------------
    
    First create a dynamic configuration for your database
    connection:
    
     from standalone.conf import settings
     settings = settings(
         DATABASE_ENGINE='sqlite3',
         DATABASE_NAME=options.database,
     )
    
    this is all you need to do to have django modules working
    in your script. You would have to add additional settings if
    you want to use more than just the ORM, for example you will
    have to add TEMPLATE_DIR if you want to use the template modules.
    
    You can add any django setting you want - standalone.conf will
    allways extend your settings, never overwrite them.
    
    Now you just define a bunch of Models, using the provided base
    class in your script. The needed module standalone.models
    reexports everything from django.models, so you only need one.
    
     from standalone import models
    
     class MyModel(models.StandaloneModel):
    
         col1 = models.CharField(max_length=1000)
         col2 = models.IntegerField()
         col3 = models.BooleanField()
    
         def __unicode__(self):
             return self.col1
    
  • 相关阅读:
    C# winIO32位,64位的使用(运行时要用管理员身份)
    C#实现的三种方式实现模拟键盘按键
    C#打印日志的小技巧
    write wall ping ifconfig mail last traceroute netstat setup mount
    安装常用工具 zip unzip bzip2 gcc gcc++编译器 cmake编译器
    gzip/gunzip tar -zcf/-zxvf zip /unzip bzip2/bunzip2 tar -cjf/tar -xjf
    help
    Asp.Net 高性能框架 SqlSugar.ORM 2.3
    centos 查看版本(转)
    浅谈OCR之Tesseract
  • 原文地址:https://www.cnblogs.com/lexus/p/2435603.html
Copyright © 2011-2022 走看看