完成models并且创建完创建完成表

main
RogerWork 1 year ago
parent 3478c2cb00
commit 5f99870a31
  1. 3
      apps/basic/apps.py
  2. 35
      apps/basic/migrations/0001_initial.py
  3. 23
      apps/basic/migrations/0002_initial.py
  4. 3
      apps/goods/apps.py
  5. 80
      apps/goods/migrations/0001_initial.py
  6. 23
      apps/goods/migrations/0002_initial.py
  7. 3
      apps/order/apps.py
  8. 68
      apps/order/migrations/0001_initial.py
  9. 34
      apps/order/migrations/0002_initial.py
  10. 2
      apps/order/models.py
  11. 3
      apps/user/apps.py
  12. 55
      apps/user/migrations/0001_initial.py
  13. 14
      myshop_back/settings.py

@ -3,4 +3,5 @@ from django.apps import AppConfig
class BasicConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'basic'
# name = 'basic'
name = 'apps.basic'

@ -0,0 +1,35 @@
# Generated by Django 4.2.4 on 2023-08-19 07:13
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Address',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('province', models.CharField(default='', max_length=50, verbose_name='省份')),
('city', models.CharField(default='', max_length=50, verbose_name='城市')),
('district', models.CharField(default='', max_length=50, verbose_name='区域')),
('address', models.CharField(default='', max_length=100, verbose_name='详细地址')),
('contact_name', models.CharField(default='', max_length=20, verbose_name='联系人')),
('contact_mobile', models.CharField(default='', max_length=11, verbose_name='联系电话')),
('is_default', models.IntegerField(default=0, verbose_name='是否是默认配送地址')),
('create_date', models.DateTimeField(default=datetime.datetime(2023, 8, 19, 15, 13, 34, 422806), verbose_name='创建时间')),
],
options={
'verbose_name': '用户配送地址',
'verbose_name_plural': '用户配送地址',
'db_table': 'd_address',
'managed': True,
},
),
]

@ -0,0 +1,23 @@
# Generated by Django 4.2.4 on 2023-08-19 07:13
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('basic', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='address',
name='user',
field=models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to=settings.AUTH_USER_MODEL, verbose_name='用户'),
),
]

@ -3,4 +3,5 @@ from django.apps import AppConfig
class GoodsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'goods'
# name = 'goods'
name = 'apps.goods'

@ -0,0 +1,80 @@
# Generated by Django 4.2.4 on 2023-08-19 07:13
import ckeditor_uploader.fields
import datetime
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Goods',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(default='', max_length=50, verbose_name='商品名称')),
('market_price', models.DecimalField(decimal_places=2, default=0, max_digits=8, verbose_name='市场价')),
('price', models.DecimalField(decimal_places=2, default=0, max_digits=8, verbose_name='实际价格')),
('unit', models.CharField(blank=True, max_length=10, null=True, verbose_name='单位')),
('click_num', models.IntegerField(default=0, verbose_name='点击数')),
('amount', models.IntegerField(default=0, verbose_name='销售量')),
('stock_num', models.IntegerField(default=0, verbose_name='库存量')),
('fav_num', models.IntegerField(default=0, verbose_name='收藏量')),
('goods_desc', ckeditor_uploader.fields.RichTextUploadingField(default='', verbose_name='商品详情')),
('status', models.IntegerField(choices=[(0, '正常'), (1, '下架')], default=0, verbose_name='商品状态')),
('main_img', models.ImageField(blank=True, null=True, upload_to='upload/goods_img', verbose_name='商品主图')),
('is_recommend', models.BooleanField(default=False, verbose_name='是否推荐')),
('create_datetime', models.DateTimeField(default=datetime.datetime(2023, 8, 19, 15, 13, 34, 431801), verbose_name='创建时间')),
],
options={
'verbose_name': '商品信息',
'verbose_name_plural': '商品信息',
'db_table': 'd_goods',
},
),
migrations.CreateModel(
name='Slide',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('create_time', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
('update_time', models.DateTimeField(auto_now=True, verbose_name='更新时间')),
('images', models.ImageField(upload_to='upload/slide_img', verbose_name='轮播图片')),
('sort', models.IntegerField(default=0, verbose_name='排序')),
('goods', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='goods.goods', verbose_name='商品')),
],
options={
'verbose_name': '首页轮播',
'verbose_name_plural': '首页轮播',
'db_table': 'd_slide',
},
),
migrations.CreateModel(
name='GoodsCategory',
fields=[
('create_time', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
('update_time', models.DateTimeField(auto_now=True, verbose_name='更新时间')),
('id', models.AutoField(primary_key=True, serialize=False)),
('name', models.CharField(default='', max_length=50, verbose_name='分类名称')),
('logo', models.ImageField(upload_to='upload/cate_img', verbose_name='分类logo图片')),
('is_nav', models.BooleanField(default=False, verbose_name='是否显示在导航栏')),
('sort', models.IntegerField(verbose_name='排序')),
('parent', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='sub_cat', to='goods.goodscategory', verbose_name='父类')),
],
options={
'verbose_name': '商品分类',
'verbose_name_plural': '商品分类',
'db_table': 'd_goods_category',
},
),
migrations.AddField(
model_name='goods',
name='category',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='goods.goodscategory', verbose_name='商品分类'),
),
]

@ -0,0 +1,23 @@
# Generated by Django 4.2.4 on 2023-08-19 07:13
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('goods', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='goods',
name='user',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, to=settings.AUTH_USER_MODEL, verbose_name='用户'),
),
]

@ -3,4 +3,5 @@ from django.apps import AppConfig
class OrderConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'order'
# name = 'order'
name = 'apps.order'

@ -0,0 +1,68 @@
# Generated by Django 4.2.4 on 2023-08-19 07:13
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
('goods', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Cart',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('goods_num', models.IntegerField(default=1, verbose_name='购物车中的商品数量')),
],
options={
'verbose_name': '购物车信息',
'verbose_name_plural': '购物车信息',
'db_table': 'd_cart',
'managed': True,
},
),
migrations.CreateModel(
name='Order',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('order_id', models.CharField(blank=True, max_length=50, null=True, verbose_name='订单号')),
('order_total', models.IntegerField(default=0, verbose_name='商品总件数')),
('order_price', models.DecimalField(decimal_places=2, default=0, max_digits=10, verbose_name='订单中金额')),
('address', models.CharField(default='', max_length=100, verbose_name='收货地址')),
('contact_name', models.CharField(default='', max_length=20, verbose_name='联系人')),
('contact_mobile', models.CharField(default='', max_length=11, verbose_name='联系电话')),
('pay_method', models.IntegerField(default=0, verbose_name='支付方式')),
('memo', models.CharField(default='', max_length=200, verbose_name='订单备注')),
('order_status', models.IntegerField(choices=[('paying', '待支付'), ('paid', '已支付'), ('shipping', '配送中'), ('complete', '订单结束'), ('cancel', '订单取消')], verbose_name='用户')),
('create_time', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
],
options={
'verbose_name': '订单信息',
'verbose_name_plural': '订单信息',
'db_table': 'd_order',
'managed': True,
},
),
migrations.CreateModel(
name='OrderGoods',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('goods_num', models.IntegerField(default=0, verbose_name='商品数量')),
('price', models.DecimalField(decimal_places=2, max_digits=10, verbose_name='下单时商品价格')),
('create_time', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
('goods', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='goods.goods', verbose_name='商品表')),
('order', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='order.order', verbose_name='订单主表')),
],
options={
'verbose_name': '订单商品信息',
'verbose_name_plural': '订单商品信息',
'db_table': 'd_order_goods',
'managed': True,
},
),
]

@ -0,0 +1,34 @@
# Generated by Django 4.2.4 on 2023-08-19 07:13
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
('goods', '0002_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('order', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='order',
name='user',
field=models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to=settings.AUTH_USER_MODEL, verbose_name='用户'),
),
migrations.AddField(
model_name='cart',
name='goods',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='goods.goods', verbose_name='商品'),
),
migrations.AddField(
model_name='cart',
name='user',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, to=settings.AUTH_USER_MODEL, verbose_name='用户'),
),
]

@ -39,7 +39,7 @@ class Order(models.Model):
contact_mobile = models.CharField(verbose_name='联系电话', max_length=11, default='')
pay_method = models.IntegerField(verbose_name='支付方式', default=0)
memo = models.CharField(verbose_name='订单备注', max_length=200, default='')
order_status = models.IntegerField(verbose_name='用户', choices=ORDER_STATUS, max_length=20)
order_status = models.IntegerField(verbose_name='用户', choices=ORDER_STATUS)
user = models.ForeignKey(verbose_name='用户', to=MyUser, on_delete=models.DO_NOTHING)
create_time = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)

@ -3,4 +3,5 @@ from django.apps import AppConfig
class UserConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'user'
# name = 'user'
name = 'apps.user'

@ -0,0 +1,55 @@
# Generated by Django 4.2.4 on 2023-08-19 07:13
import django.contrib.auth.models
import django.contrib.auth.validators
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
initial = True
dependencies = [
('auth', '0012_alter_user_first_name_max_length'),
]
operations = [
migrations.CreateModel(
name='MyUser',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')),
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('true_name', models.CharField(blank=True, max_length=50, verbose_name='真实姓名')),
('mobile', models.CharField(default='', max_length=11, verbose_name='手机号码')),
('sex', models.IntegerField(choices=[(0, ''), (1, '')], verbose_name='性别')),
('birthday', models.DateField(blank=True, null=True, verbose_name='生日')),
('nickname', models.CharField(blank=True, max_length=50, verbose_name='昵称')),
('user_img', models.ImageField(default='', upload_to='user_mage', verbose_name='头像')),
('level', models.IntegerField(choices=[(1, '寂寞卡会员'), (2, '钻石卡会员'), (3, '金卡会员'), (4, '银卡会员')], verbose_name='用户级别')),
('status', models.IntegerField(choices=[(0, '正常'), (1, '异常')], verbose_name='用户状态')),
('create_time', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
('update_time', models.DateTimeField(auto_now=True, verbose_name='更新时间')),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')),
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')),
],
options={
'verbose_name': 'user',
'verbose_name_plural': 'users',
'permissions': (['check_myuer', '审核用户信息'],),
'abstract': False,
},
managers=[
('objects', django.contrib.auth.models.UserManager()),
],
),
]

@ -28,7 +28,7 @@ DEBUG = True
ALLOWED_HOSTS = []
# Application definition
sys.path.insert(0, os.path.join(BASE_DIR, 'apps'))
# sys.path.insert(0, os.path.join(BASE_DIR, 'apps')) # 导入包, 不到入的话可以在apps中修改name为apps.name
INSTALLED_APPS = [
'django.contrib.admin',
@ -37,7 +37,7 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'apps.basic.apps.BasicConfig',
'apps.basic',
'apps.goods',
'apps.order',
'apps.user',
@ -131,5 +131,13 @@ STATIC_URL = 'static/'
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
CKEDITOR_UPLOAD_PATH = 'upload/full_text'
CKEDITOR_UPLOAD_PATH = 'upload/full_text'
"""
遇到此报错后需要修改用户验证的model
ERRORS:
auth.User.groups: (fields.E304) Reverse accessor 'Group.user_set' for 'auth.User.groups' clashes with reverse accessor for 'user.MyUser.groups'.
HINT: Add or change a related_name argument to the definition for 'auth.User.groups' or 'user.MyUser.groups'.
"""
AUTH_USER_MODEL = 'user.Myuser'

Loading…
Cancel
Save