(venv) ➜ storeProject python manage.py makemigrations Migrations for 'goods': goods/migrations/0001_initial.py - Create model Goods (venv) ➜ storeProject python manage.py migrate Operations to perform: Apply all migrations: admin, auth, contenttypes, goods, sessions Running migrations: Applying contenttypes.0001_initial... OK Applying auth.0001_initial... OK Applying admin.0001_initial... OK Applying admin.0002_logentry_remove_auto_add... OK Applying admin.0003_logentry_add_action_flag_choices... OK Applying contenttypes.0002_remove_content_type_name... OK Applying auth.0002_alter_permission_name_max_length... OK Applying auth.0003_alter_user_email_max_length... OK Applying auth.0004_alter_user_username_opts... OK Applying auth.0005_alter_user_last_login_null... OK Applying auth.0006_require_contenttypes_0002... OK Applying auth.0007_alter_validators_add_error_messages... OK Applying auth.0008_alter_user_username_max_length... OK Applying auth.0009_alter_user_last_name_max_length... OK Applying auth.0010_alter_group_name_max_length... OK Applying auth.0011_update_proxy_permissions... OK Applying auth.0012_alter_user_first_name_max_length... OK Applying goods.0001_initial... OK Applying sessions.0001_initial... OK (venv) ➜
至此完成了模型的创建和数据的迁移操作
添加数据
接下来使用 admin 控制台来添加数据
创建超级管理员
使用命令创建一个超级管理员用户
python manage.py createsuperuser
创建一个名称为:admin,密码为:admin 的超级用户
1 2 3 4 5 6 7 8 9 10
(venv) ➜ storeProject python manage.py createsuperuser Username (leave blank to use 'zachary'): admin Email address: Password: Password (again): The password is too similar to the username. This password is too short. It must contain at least 8 characters. This password is too common. Bypass password validation and create user anyway? [y/N]: y Superuser created successfully.
注册数据模型
在 goods 应用下的 admin.py 中注册 goods 数据模型
1 2 3 4 5 6 7
from django.contrib import admin
from . import models
# Register your models here. admin.site.register(models.Goods)
# -*- coding:utf-8 -*- # Author: Zachary from rest_framework import status from rest_framework.decorators import api_view from rest_framework.response import Response
from api.serializers import GoodsSerializer from goods.models import Goods
# -*- coding:utf-8 -*- # Author: Zachary from rest_framework import status from rest_framework.decorators import api_view from rest_framework.response import Response
from api.serializers import GoodsSerializer from goods.models import Goods