0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
电子发烧友
开通电子发烧友VIP会员 尊享10大特权
海量资料免费下载
精品直播免费看
优质内容免费畅学
课程9折专享价
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

Python版超市管理系統(tǒng)源代碼

汽車電子技術(shù) ? 來源:Python代碼大全 ? 作者: Python代碼狂人 ? 2023-02-24 09:59 ? 次閱讀

Python版超市管理系統(tǒng)源代碼,基于django+mysql安裝步驟

1、在mysql中創(chuàng)建名為demo_django_supermarket的數(shù)據(jù)庫,修改config/setting.py中數(shù)據(jù)庫用戶及密碼

CREATE DATABASE demo_django_supermarket DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

2、pip install -r requirements

3、初始化數(shù)據(jù)庫:manage.py migrate

4、設(shè)置一個超級管理員 admin (admin@123456)

manage.py loaddata fixtures/root_manager.yaml

5、啟動服務(wù)

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  # 時區(qū)




# 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 = "供應(yīng)商%d" % i
        p.address = "(%s)請關(guān)注公眾號:Python代碼大全" % p.name
        p.phone = "15512345678%d" % i
        p.save()




def init_goods(apps, args):
    category_map = {
        0: "零食飲料",
        1: "生鮮果蔬",
        2: "糧油副食",
        3: "清潔用品",
        4: "家居家電",
    }


    # 循環(huán) /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)


    # 復(fù)制+改名 成 /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()
        # 隨機(jī)造數(shù)據(jù)
        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

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報投訴
  • 源代碼
    +關(guān)注

    關(guān)注

    96

    文章

    2949

    瀏覽量

    67544
  • MySQL
    +關(guān)注

    關(guān)注

    1

    文章

    840

    瀏覽量

    27310
  • python
    +關(guān)注

    關(guān)注

    56

    文章

    4822

    瀏覽量

    85817
收藏 0人收藏

    評論

    相關(guān)推薦

    酒店管理系統(tǒng)源代碼

    酒店管理系統(tǒng)源代碼
    發(fā)表于 07-19 11:09 ?117次下載

    圖書館管理系統(tǒng)源代碼

    圖書館管理系統(tǒng)源代碼
    發(fā)表于 07-19 11:11 ?17次下載

    財務(wù)管理系統(tǒng)源代碼

    財務(wù)管理系統(tǒng)源代碼
    發(fā)表于 07-19 11:12 ?346次下載

    生產(chǎn)管理系統(tǒng)源代碼

    生產(chǎn)管理系統(tǒng)源代碼
    發(fā)表于 07-19 11:12 ?13次下載

    人事管理系統(tǒng)vf源代碼

    人事管理系統(tǒng)vf源代 這是一款不錯的源代碼,值得借簽.
    發(fā)表于 02-26 16:34 ?159次下載

    學(xué)籍管理源代碼

    學(xué)籍管理源代碼 學(xué)生插入,獎勵,管理
    發(fā)表于 04-09 15:14 ?62次下載

    C語言圖書管理系統(tǒng)源代碼下載

    C語言圖書管理系統(tǒng)源代碼
    發(fā)表于 03-24 11:59 ?24次下載

    Python微服務(wù)開發(fā)的源代碼合集免費下載

    本文檔的主要內(nèi)容詳細(xì)介紹的是Python微服務(wù)開發(fā)的源代碼合集免費下載。
    發(fā)表于 09-20 08:00 ?3次下載

    python實現(xiàn)目標(biāo)檢測的源代碼免費下載

    本文檔的主要內(nèi)容詳細(xì)介紹的是python實現(xiàn)目標(biāo)檢測的源代碼免費下載
    發(fā)表于 04-09 08:00 ?6次下載
    <b class='flag-5'>python</b>實現(xiàn)目標(biāo)檢測的<b class='flag-5'>源代碼</b>免費下載

    python文件讀取的源代碼免費下載

    本文檔的主要內(nèi)容詳細(xì)介紹的是python文件讀取的源代碼免費下載。
    發(fā)表于 08-07 17:14 ?20次下載
    <b class='flag-5'>python</b>文件讀取的<b class='flag-5'>源代碼</b>免費下載

    家庭財務(wù)管理系統(tǒng)課程設(shè)計及源代碼

    家庭財務(wù)管理系統(tǒng)課程設(shè)計及源代碼
    發(fā)表于 07-08 09:41 ?17次下載

    Python版警察抓小偷游戲源代碼

    Python版警察抓小偷游戲源代碼,有多個難度級別,直接運行g(shù)ame.py,輸入難度級別(1-13)。不同的難度等級對應(yīng)不同的圖形。
    的頭像 發(fā)表于 02-24 09:56 ?2039次閱讀
    <b class='flag-5'>Python</b>版警察抓小偷游戲<b class='flag-5'>源代碼</b>

    Python版實驗室設(shè)備管理系統(tǒng)源代碼

    Python版實驗室設(shè)備管理系統(tǒng)源代碼、實驗室儀器借用記錄基于PySide2+sqlite3,用Pyside2開發(fā)的儀器借用記錄系統(tǒng),儲存數(shù)
    的頭像 發(fā)表于 02-24 10:20 ?2839次閱讀
    <b class='flag-5'>Python</b>版實驗室設(shè)備<b class='flag-5'>管理</b><b class='flag-5'>系統(tǒng)</b><b class='flag-5'>源代碼</b>

    Python編程實戰(zhàn)(源代碼)

    [源代碼]Python編程實戰(zhàn) 妙趣橫生的項目之旅
    發(fā)表于 06-06 17:49 ?3次下載

    [源代碼]Python算法詳解

    [源代碼]Python算法詳解[源代碼]Python算法詳解
    發(fā)表于 06-06 17:50 ?8次下載

    電子發(fā)燒友

    中國電子工程師最喜歡的網(wǎng)站

    • 2931785位工程師會員交流學(xué)習(xí)
    • 獲取您個性化的科技前沿技術(shù)信息
    • 參加活動獲取豐厚的禮品