0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
会员中心
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

Python版超市管理系统源代码

汽车电子技术 来源:Python代码大全 作者: Python代码狂人 2023-02-24 09:59 次阅读

Python版超市管理系统源代码,基于django+mysql安装步骤

1、在mysql中创建名为demo_django_supermarket的数据库,修改config/setting.py中数据库用户及密码

CREATE DATABASE demo_django_supermarket DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

2、pip install -r requirements

3、初始化数据库:manage.py migrate

4、设置一个超级管理员 admin (admin@123456)

manage.py loaddata fixtures/root_manager.yaml

5、启动服务

manage.py runserver localhost:8001

完整程序源代码下载地址:

https://download.csdn.net/download/weixin_42756970/86819049

程序运行截图

图片图片

图片

图片

后台管理

图片

图片

setting.py

"""
Django settings for config project.


Generated by 'django-admin startproject' using Django 2.1.4.


For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/


For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""


import os


# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/


# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '_joao(!w!oc6ktbxr55x4$ioy4$#u6#09cx$st=pp3sj(6lm!)'


# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True


ALLOWED_HOSTS = ['*',
                 # '127.0.0.1',
                 # '10.10.10.154',
                 # '120.229.216.9'
                 ]


# Application definition


INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'app',
    'gunicorn',
]


MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]


ROOT_URLCONF = 'config.urls'


TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR, os.path.join('templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]


WSGI_APPLICATION = 'config.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases




DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'HOST': '127.0.0.1',
        'PORT': '3306',
        'NAME': 'demo_django_supermarket',
        'USER': 'root',
        'PASSWORD': 'sxing86',
        'OPTIONS': {
            'charset': 'utf8mb4'
        }
    }
}


# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators


AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/


LANGUAGE_CODE = 'zh-hans'


TIME_ZONE = 'Asia/Shanghai'


USE_I18N = True


USE_L10N = True


USE_TZ = False
# USE_TZ = True  # 时区




# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/


STATIC_URL = '/static/'


STATIC_PATH = os.path.dirname(os.path.abspath(__file__))
STATIC_PATH = os.path.join(STATIC_PATH, '../')


STATICFILES_DIRS = (
    os.path.join(STATIC_PATH, 'static/'),
)


MEDIA_ROOT = os.path.join(BASE_DIR, 'static/media')

0001_initial.py

# Generated by Django 2.2.2 on 2022-03-16 18:26


from django.db import migrations, models




class Migration(migrations.Migration):


    initial = True


    dependencies = [
    ]


    operations = [
        migrations.CreateModel(
            name='Goods',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=20)),
                ('sale_price', models.FloatField()),
                ('cost_price', models.FloatField()),
                ('weight', models.FloatField()),
                ('sort', models.IntegerField()),
                ('produce_date', models.DateField()),
                ('limit_date', models.DateField()),
                ('lower', models.FloatField(default=0)),
                ('isDelete', models.BooleanField(default=False)),
            ],
        ),
        migrations.CreateModel(
            name='Manager',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('account', models.CharField(max_length=20)),
                ('pwd', models.CharField(max_length=40)),
                ('name', models.CharField(max_length=20)),
                ('gender', models.IntegerField(default=0)),
                ('phone', models.CharField(max_length=11)),
                ('authority', models.IntegerField(default=0)),
                ('isDelete', models.BooleanField(default=0)),
            ],
        ),
        migrations.CreateModel(
            name='Message',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('time', models.DateTimeField(auto_now=True)),
                ('type', models.IntegerField()),
                ('content', models.TextField()),
                ('contact', models.CharField(max_length=20)),
                ('name', models.CharField(max_length=20)),
                ('isRead', models.BooleanField(default=False)),
            ],
        ),
        migrations.CreateModel(
            name='Provider',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=20)),
                ('address', models.CharField(max_length=40)),
                ('phone', models.CharField(max_length=11)),
                ('isDelete', models.BooleanField(default=False)),
            ],
        ),
        migrations.CreateModel(
            name='Record',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('location', models.IntegerField()),
                ('date', models.DateField(auto_now=True)),
                ('purchase_num', models.IntegerField(null=True)),
                ('sale_num', models.IntegerField(null=True)),
                ('withdraw_num', models.IntegerField(null=True)),
                ('goods', models.ForeignKey(on_delete=True, to='app.Goods')),
            ],
        ),
        migrations.AddField(
            model_name='goods',
            name='provider',
            field=models.ForeignKey(on_delete=True, to='app.Provider'),
        ),
    ]

0002_initial_data.py

# Generated by Django 2.2.2 on 2022-03-16 18:26
import datetime
import os
import random
import shutil


from django.db import migrations




def init_manager(apps, args):
    Manager = apps.get_model('app', 'Manager')
    Manager(
        account="admin",
        pwd="123456",
        name="admin",
        gender=1,
        phone="15512345678",
    ).save()




def init_providers(apps, args):
    provider = apps.get_model('app', 'Provider')
    for i in range(3):
        p = provider()
        p.name = "供应商%d" % i
        p.address = "(%s)请关注公众号:Python代码大全" % p.name
        p.phone = "15512345678%d" % i
        p.save()




def init_goods(apps, args):
    category_map = {
        0: "零食饮料",
        1: "生鲜果蔬",
        2: "粮油副食",
        3: "清洁用品",
        4: "家居家电",
    }


    # 循环 /static/media/resources/goods/*
    current_path = os.path.dirname(os.path.abspath(__file__))


    current_path = current_path.replace("app\\migrations", "")


    resource_img_dir = "%s/static/media/resources/goods" % current_path
    upload_img_dir = "%s/static/media/goods_img" % current_path


    files = [f for f in os.listdir(resource_img_dir) if os.path.isfile(os.path.join(resource_img_dir, f))]
    print(files)


    # 复制+改名 成 /static/media/goods_img/{category_num}_{good_id}.jpg
    date_now = datetime.datetime.utcnow()
    good = apps.get_model('app', 'Goods')
    record = apps.get_model('app', 'Record')
    for index, f in enumerate(files):
        category_id = random.randrange(0, 5)
        provider_id = random.randrange(1, 4)
        cost_price = random.randrange(5, 100)
        sale_price = cost_price + random.randrange(5, 20)


        produce_date = date_now - datetime.timedelta(days=(category_id + 1) * 365)
        limit_date = date_now + datetime.timedelta(days=(category_id + 1) * 365)
        purchase_date = produce_date + datetime.timedelta(days=cost_price)
        sale_date = purchase_date + datetime.timedelta(days=sale_price)


        # total = good.objects.count()
        # 随机造数据
        g = good(
            name=category_map[category_id] + str(index),
            sort=category_id,
            cost_price=float(cost_price),
            sale_price=float(sale_price),
            produce_date=produce_date,
            limit_date=limit_date,
            weight=float(sale_price + cost_price),
            provider_id=provider_id,
        )
        # g.id = total+1
        g.save()


        image_path = "%s/%d_%d.png" % (upload_img_dir, category_id, g.id)
        shutil.copyfile("%s/%s" % (resource_img_dir, f), image_path)


        location_id = random.randrange(0, 8)
        record(
            location=location_id,
            purchase_num=sale_price * cost_price,
            goods_id=g.id,
            date=purchase_date,
        ).save()
        record(
            location=location_id,
            goods_id=g.id,
            date=sale_date,
            sale_num=sale_price * cost_price / (location_id + 1),
        ).save()




class Migration(migrations.Migration):
    dependencies = [
        ('app', '0001_initial'),
    ]


    operations = [
        migrations.RunPython(init_providers),
        migrations.RunPython(init_goods),
        migrations.RunPython(init_manager),
    ]

完整程序源代码下载地址:

https://download.csdn.net/download/weixin_42756970/86819049

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • 源代码
    +关注

    关注

    96

    文章

    2944

    浏览量

    66638
  • MySQL
    +关注

    关注

    1

    文章

    799

    浏览量

    26413
  • python
    +关注

    关注

    55

    文章

    4777

    浏览量

    84407
收藏 人收藏

    评论

    相关推荐

    酒店管理系统源代码

    酒店管理系统源代码
    发表于 07-19 11:09 117次下载

    图书馆管理系统源代码

    图书馆管理系统源代码
    发表于 07-19 11:11 17次下载

    财务管理系统源代码

    财务管理系统源代码
    发表于 07-19 11:12 346次下载

    生产管理系统源代码

    生产管理系统源代码
    发表于 07-19 11:12 13次下载

    教务管理系统源代码

    教务管理系统源代码 主页登录部分   default.asp
    发表于 02-09 15:31 69次下载

    人事管理系统vf源代码

    人事管理系统vf源代 这是一款不错的源代码,值得借签.
    发表于 02-26 16:34 159次下载

    学籍管理源代码

    学籍管理源代码 学生插入,奖励,管理
    发表于 04-09 15:14 62次下载

    C语言图书管理系统源代码下载

    C语言图书管理系统源代码
    发表于 03-24 11:59 24次下载

    Python微服务开发的源代码合集免费下载

    本文档的主要内容详细介绍的是Python微服务开发的源代码合集免费下载。
    发表于 09-20 08:00 3次下载

    python文件读取的源代码免费下载

    本文档的主要内容详细介绍的是python文件读取的源代码免费下载。
    发表于 08-07 17:14 20次下载
    <b class='flag-5'>python</b>文件读取的<b class='flag-5'>源代码</b>免费下载

    家庭财务管理系统课程设计及源代码

    家庭财务管理系统课程设计及源代码
    发表于 07-08 09:41 17次下载

    Python版警察抓小偷游戏源代码

    Python版警察抓小偷游戏源代码,有多个难度级别,直接运行game.py,输入难度级别(1-13)。不同的难度等级对应不同的图形。
    的头像 发表于 02-24 09:56 1634次阅读
    <b class='flag-5'>Python</b>版警察抓小偷游戏<b class='flag-5'>源代码</b>

    Python版实验室设备管理系统源代码

    Python版实验室设备管理系统源代码、实验室仪器借用记录基于PySide2+sqlite3,用Pyside2开发的仪器借用记录系统,储存数
    的头像 发表于 02-24 10:20 2205次阅读
    <b class='flag-5'>Python</b>版实验室设备<b class='flag-5'>管理</b><b class='flag-5'>系统</b><b class='flag-5'>源代码</b>

    Python编程实战(源代码)

    [源代码]Python编程实战 妙趣横生的项目之旅
    发表于 06-06 17:49 3次下载

    [源代码]Python算法详解

    [源代码]Python算法详解[源代码]Python算法详解
    发表于 06-06 17:50 0次下载