- 工程目录下创建目录: fixtures
- settings.py 增加设置: FIXTURE_DIRS = (os.path.join(BASE_DIR,'fixtures',),)
- 编写初始化数据文件: initial_data 后缀可以根据自己的为.json .yaml 等
注意:django自带user的model为:auth.User, 不要写成django.contrib.auto.User
# initial_data.yaml
# initial date for vidsai pin
- model: auth.User
pk: 1
fields:
username: abeladmin
email: 972237007@qq.com
password: abeladmin
is_superuser: 1
is_staff: 1
- model: auth.User
pk: 2
fields:
username: abeltest
email: 972237007@qq.com
password: abeltest
is_superuser: 0
is_staff: 0
- model: upload.Album
pk: 1
fields:
album_name: abeltest
user_id: 2
album_status: 1
create_time: 2017-01-01 20:00:00
update_time: 2017-01-01 20:00:00
- model: upload.Media
pk: 1
fields:
album_id: 1
user_id: 2
media_name: AbelTestJpg
file: pin/1.jpg
media_type: 1
media_status: 1
create_time: 2017-01-01 20:00:00
- model: upload.Media
pk: 2
fields:
album_id: 1
user_id: 2
media_name: AbelTestMp4
file: pin/1.mp4
media_type: 2
media_status: 1
create_time: 2017-01-01 20:00:00
- 执行:python manage.py loaddata initial_data.yaml
网友评论