默认情况下一个django app的所有模型都保存在一个叫models.py的文件中、这样事实是不方便管理的;
通过包来组织模型是比较方便的。
一、第一步:删除models.py:
rm -rf models.py
二、第二步:创建models目录、并增加标记文件__init__.py:
mkdir models
touch models/__init__.py
三、例子:
1、
2、
3、
4、
python3 manage.py shell
Python 3.6.2 (v3.6.2:5fd33b5926, Jul 16 2017, 20:11:06)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import django
>>> django.setup()
>>> from polls.models import Person,Student
>>> s=Student()
>>> s.name='welson'
>>> s.sid=1
>>> s
<Student: I am welson my sid is 1>
----