国庆有点懒散更新的内容不多,大家国庆快乐
上次写到点我查看
设置中国时区修改表单存储位置设计商品相关的表,主要是总库存,退货,进货,销售优化登入验证码,去除1iO0
这些让人难以区分的内容重新设计文件目录二.配置相关setting.py
"""Django settings for drf_test project.Generated by 'django-admin startproject' using Django 1.11.22.For more information on this file,seehttps://docs.djangoproject.com/en/1.11/topics/settings/For the full List of settings and their values,seehttps://docs.djangoproject.com/en/1.11/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/1.11/howto/deployment/checkList/# Security WARNING: keep the secret key used in production secret!SECRET_KEY = 'ppa5l3jvxr4k^ow*4o+0_^7@&sa3x+!hb_$artwraa%60iq@g7'# Security WARNING: don't run with deBUG turned on in production!DEBUG = TrueALLOWED_HOSTS = []# Application deFinitionINSTALLED_APPS = [ 'django.contrib.admin','django.contrib.auth','django.contrib.ContentTypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles','drf_API',]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 = 'drf_test.urls'TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates','Dirs': [os.path.join(BASE_DIR,'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 = 'drf_test.wsgi.application'# Database# https://docs.djangoproject.com/en/1.11/ref/settings/#databasesDATABASES = { 'default': { 'ENGINE': 'django.db.backends.MysqL',# 数据库引擎 'name': 'mib',# 你要存储数据的库名,事先要创建之 'USER': 'root',# 数据库用户名 'PASSWORD': '16745',# 密码 'HOST': 'localhost',# IP 'PORT': '3306',# 数据库使用的端口 }}# Password valIDation# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-valIDatorsAUTH_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/1.11/topics/i18n/LANGUAGE_CODE = 'zh-hans'TIME_ZONE = 'Asia/Shanghai'USE_I18N = TrueUSE_L10N = TrueUSE_TZ = False# Static files (CSS,JavaScript,Images)# https://docs.djangoproject.com/en/1.11/howto/static-files/STATIC_URL = '/static/'STATICfileS_Dirs=(os.path.join(BASE_DIR,'static'),)AUTH_USER_MODEL = "drf_API.UserInfo"MEDIA_URL = "/img/"MEDIA_ROOT = os.path.join(BASE_DIR,"img")
三.验证码相关from django.shortcuts import render,httpResponse,redirectfrom django.http import JsonResponsefrom PIL import Image,ImageDraw,ImageFontimport randomfrom io import BytesIOfrom django.contrib import authfrom drf_API.userinfo_form import Registerfrom drf_API import modelsfrom rest_framework.throttling import SimpleRateThrottledef test(request): return render(request,'aa.HTML')def register(request): if request.method=='GET': form=Register() return render(request,'register.HTML',{'form':form}) elif request.is_AJAX(): response={'code':100,'msg':None} form = Register(request.POST) if form.is_valID(): #校验通过的数据 clean_data=form.cleaned_data #把re_pwd剔除 clean_data.pop('re_pwd') #取出头像 avatar=request.fileS.get('avatar') if avatar: clean_data['avatar']=avatar user=models.UserInfo.objects.create_user(**clean_data) if user: response['msg'] = '创建成功' else: response['code'] = 103 response['msg'] = '创建失败' else: response['code']=101 #把校验不通过的数据返回 response['msg']=form.errors print(type(form.errors)) return JsonResponse(response,safe=False)def login(request): if request.method=='GET': return render(request,'login.HTML') else: print(request.POST) user_name=request.POST.get('name') pwd=request.POST.get('pwd') code=request.POST.get('code') user=auth.authenticate(username=user_name,password=pwd) print(user) if request.session.get('code').upper() !=code.upper(): #忽略大小写 return httpResponse('验证码错误') elif not user: return httpResponse('账号密码错误') else: auth.login(request,user) return httpResponse('登入成功')def get_code(request): if request.method == 'GET': img = Image.new('RGB',(350,40),(random.randint(0,255),random.randint(0,255))) # 写文字 # 生成一个字体对象 Font = ImageFont.truetype('/static/Gabriola.ttf',34) # 调用方法,返回一个画板对象 draw = ImageDraw.Draw(img) new_text ='' x = 100 # 生成随机8位数字 text_chiose = 'zxcvbnmasdfghjklqwertyup23456789ZXCVBNMASDFGHJKLQWERTYUP' text_List=random.sample(text_chiose,8) for text in text_List: x+=20 y = random.randint(1,5) draw.text((x,y),text,255)),Font=Font) new_text +=text # 加点线 wIDth = 320 height = 35 for i in range(2): x1 = random.randint(0,wIDth) x2 = random.randint(0,wIDth) y1 = random.randint(0,height) y2 = random.randint(0,height) # 在图片上画线 draw.line((x1,y1,x2,y2),fill=(random.randint(0,255))) for i in range(10): # 画点 draw.point([random.randint(0,wIDth),height)],255))) x = random.randint(0,wIDth) y = random.randint(0,height) # 画弧形 draw.arc((x,y,x + 4,y + 4),90,255))) print(new_text) #存在session中 request.session['code']=new_text #存内存 f = BytesIO() img.save(f,'png') return httpResponse(f.getvalue())
四.模型相关from django.db import modelsfrom django.contrib.auth.models import AbstractUserfrom rest_framework import mixins# Create your models here.class UserInfo(AbstractUser): avatar = models.fileFIEld(upload_to='avatar/',default='avatar/default.png') class Meta: verbose_name='用户表' verbose_name_plural = verbose_nameclass commodity(models.Model): ID = models.SmallintegerFIEld(primary_key=True,db_column='序号') name = models.CharFIEld(max_length=60,db_column='商品名',null=True) inventory = models.IntegerFIEld(db_column='库存',null=True) cost = models.DecimalFIEld (max_digits=60,decimal_places=2,db_column='单件成本',null=True) selling_price= models.DecimalFIEld (max_digits=60,db_column='销售价格',null=True) quantity_in = models.IntegerFIEld(db_column='进货总数量',null=True) sales_volume = models.IntegerFIEld(db_column='销售量总数量',null=True) return_volume = models.IntegerFIEld(db_column='退货总数量',null=True) is_delete = models.BooleanFIEld(default=False,db_column='是否删除') def __str__(self): return self.name class Meta: db_table = "库存表"class DaySales(models.Model): ID = models.SmallintegerFIEld(primary_key=True,db_column='日期序号') date = models.DateTimeFIEld(auto_Now_add=True,db_column='日期') number = models.DecimalFIEld(max_digits=60,db_column='营业总额',db_column='是否删除') date_changed = models.DateTimeFIEld(auto_Now=True,db_column='最后修改日期') def __str__(self): return self.date class Meta: db_table = "日销售表"class DayStock(models.Model): ID = models.SmallintegerFIEld(primary_key=True,db_column='日期') number = models.DecimalFIEld(max_digits=60,db_column='进货总额',db_column='最后修改日期') def __str__(self): return self.date class Meta: db_table = "日进货表"class DayReturn(models.Model): ID = models.SmallintegerFIEld(primary_key=True,db_column='退货总额',db_column='最后修改日期') def __str__(self): return self.date class Meta: db_table = "日退货表"class commoditySales(models.Model): ID = models.SmallintegerFIEld(primary_key=True,db_column='日期序号') name = models.CharFIEld(max_length=60,null=True) data = models.ForeignKey('DaySales','ID',db_column='销售日期',null=True) sales_volume = models.IntegerFIEld(db_column='销售量数量',null=True) batch = models.IntegerFIEld(db_column='批号',db_column='最后修改日期') def __str__(self): return self.name class Meta: db_table = "商品销售表"class commodityStock(models.Model): ID = models.SmallintegerFIEld(primary_key=True,null=True) data = models.ForeignKey('DayStock',db_column='进货日期',null=True) Stock_volume = models.IntegerFIEld( db_column='进货数量',db_column='最后修改日期') def __str__(self): return self.name class Meta: db_table = "商品进货表"class commodityReturn(models.Model): ID = models.SmallintegerFIEld(primary_key=True,null=True) data = models.ForeignKey('DayReturn',db_column='退货日期',db_column='退货价格',null=True) return_volume = models.IntegerFIEld( db_column='退货数量',db_column='最后修改日期') def __str__(self): return self.name class Meta: db_table = "商品退货表"
总结 以上是内存溢出为你收集整理的国庆续写商品管理系统(二)全部内容,希望文章能够帮你解决国庆续写商品管理系统(二)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)