Python版超市管理系統(tǒng)源代碼,基于django+mysql安裝步驟
1、在mysql中創(chuàng)建名為demo_django_supermarket的數(shù)據(jù)庫(kù),修改config/setting.py中數(shù)據(jù)庫(kù)用戶及密碼
CREATE DATABASE demo_django_supermarket DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
2、pip install -r requirements
3、初始化數(shù)據(jù)庫(kù):manage.py migrate
4、設(shè)置一個(gè)超級(jí)管理員 admin (admin@123456)
manage.py loaddata fixtures/root_manager.yaml
5、啟動(dòng)服務(wù)
manage.py runserver localhost:8001
完整程序源代碼下載地址:
https://download.csdn.net/download/weixin_42756970/86819049
程序運(yùn)行截圖




后臺(tái)管理


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  # 時(shí)區(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)請(qǐng)關(guān)注公眾號(hào):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
- 
                                源代碼
                                +關(guān)注
關(guān)注
96文章
2953瀏覽量
69470 - 
                                MySQL
                                +關(guān)注
關(guān)注
1文章
893瀏覽量
29108 - 
                                python
                                +關(guān)注
關(guān)注
56文章
4850瀏覽量
89313 
發(fā)布評(píng)論請(qǐng)先 登錄
Python微服務(wù)開(kāi)發(fā)的源代碼合集免費(fèi)下載
使用Python按行讀文件的源代碼免費(fèi)下載
    
家庭財(cái)務(wù)管理系統(tǒng)課程設(shè)計(jì)及源代碼
Python版警察抓小偷游戲源代碼
    
Python版實(shí)驗(yàn)室設(shè)備管理系統(tǒng)源代碼
    
          
        
        
Python版超市管理系統(tǒng)源代碼
                
 
    
           
            
            
                
            
評(píng)論