django 购物系统 - 创建模型
来源:互联网 发布:如何把腓肠肌变小知乎 编辑:程序博客网 时间:2024/05/03 02:35
1. 前置准备
ER图 - 实体关系模型设计
UML类图 - 类的设计
2.Category模型
3.Product模型
4 django常用字段类型
BooleanField
CharField
TextField
DateField
DateTimeField
DecimalField
FileField
FilePathField
FloatField
ImageField 需要安装Pillow
IntegerField
SlugField
安装Pillow
sudo apt-get install libjpeg-dev
pip install --no-cache-dir -I Pillow
生成requirements.txt 用于安装依赖
cd /home/vagrant/shopsys
pyenv activate shopsysenv
pip freeze > requirements.txt
例子
from django.db import modelsfrom django.core.urlresolvers import reverse# Create your models here.class Category(models.Model): name = models.CharField("名称", max_length=50) slug = models.SlugField( "Slug", max_length=50, unique=True, help_text='根据name生成的, 用于生成页面URL,必须唯一' ) description = models.TextField("描述") is_active = models.BooleanField("是否激活", default=True) meta_keywords = models.CharField( "Meta 关键词", max_length=255, help_text="meta关键词, 有利于SEO, 用逗号分隔" ) meta_description = models.CharField( "Meta描述", max_length=255, help_text="Meta描述" ) created_at = models.DateTimeField("创建时间", auto_now_add=True) updated_at = models.DateTimeField("更新时间", auto_now=True) class Meta: db_table = 'categories' ordering = ['-created_at'] verbose_name_plural = 'Categories' def __str__(self): return self.name def get_absolute_url(self): return reverse('catalog_category', args=(self.slug,))class Product(models.Model): name = models.CharField("名称", max_length=255, unique=True) slug = models.SlugField( "Slug", max_length=255, unique=True, help_text='根据name生成的, 用于生成页面URL,必须唯一', ) brand = models.CharField("品牌", max_length=50) sku = models.CharField("计量单位", max_length=50) price = models.DecimalField("价格", max_digits=9, decimal_places=2) old_price = models.DecimalField("旧价格", max_digits=9, decimal_places=2, blank=True, default=0.00) image = models.ImageField("图片", max_length=50) is_active = models.BooleanField("设为激活", default=True) is_bestseller = models.BooleanField("设为畅销", default=False) is_featured = models.BooleanField("设为推荐", default=False) quantity = models.IntegerField("数量") meta_keywords = models.CharField("Meta关键词", max_length=255, help_text='meta 关键词标签 逗号分隔') meta_description = models.CharField("Meta描述", max_length=255, help_text='Meta描述标签') created_at = models.DateTimeField("创建时间", auto_now_add=True) updated_at = models.DateTimeField("更新时间", auto_now=True) categories = models.ManyToManyField(Category) class Meta: db_table = 'products' ordering = ['-created_at'] def __str__(self): return self.name def get_absolute_url(self): return reverse('catalog_product', args=(self.slug,)) def sale_price(self): if self.old_price > self.price: return self.price else: return None
0 0
- django 购物系统 - 创建模型
- django 购物系统 - Zsh
- django 购物系统 mysql
- django 购物系统 - session
- django 购物系统 - 购物车模型
- django 购物系统 - 购物车模型
- django 购物系统 - 环境准备
- django 购物系统 - 开发环境搭建
- django 购物系统 - 代码传到github
- django 购物系统 - admin注册和验证
- django 购物系统 - 添加至购物车表单
- django 购物系统 - 添加至购物车表单
- Django项目-数据库,模型创建
- [Django数据库模型]创建我们第一个Django模型
- django学习之三:model模型创建
- Django学习笔记4-创建模型
- python django框架的模型的创建
- 创建 Django 博客的数据库模型
- Kibana的安装与调试
- 主题:Gradle打包 作用:为不同的应用市场生成相应的apk
- Ganglia环境搭建并监控Hadoop分布式集群
- 258. Add Digits #Easy
- 范数概念
- django 购物系统 - 创建模型
- UITabbarController使用(二)隐藏和显示tabbar
- Exercise(16):排列组合
- python——时间与时间戳之间的转换
- U-Boot移植--环境变量保存位置
- Android之绘图
- 百度2016暑假实习机试题(部分)
- 访问局域网服务器中的服务
- 利用Requests爬取图片与网页数据