Django执行离线ORM、数据操作

  1. django执行离线ORM操作,方法1
import os

if __name__ == '__main__':
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "orm_demo.settings")
    import django
    django.setup()

    from app01 import models
  1. django执行离线ORM操作,方法2
#1
python manage.py shell

#2
from snippets.models import Snippet
from snippets.serializers import SnippetSerializer
from rest_framework.renderers import JSONRenderer
from rest_framework.parsers import JSONParser

snippet = Snippet(code='foo = "bar"\n')
snippet.save()

snippet = Snippet(code='print "hello, world"\n')
snippet.save()
  1. django数据库操作

python manage.py inspectdb

python manage.py inspectdb

posted @ 2020-12-07 16:04  该显示昵称已被使用了  阅读(83)  评论(0编辑  收藏  举报