一:组合搜索
组合搜索可以用来实现快速查询。效果图举例。瓜子网站选车
注意:URL中的地址0-0什么的是传递的参数的值。
二:实现组合搜索
组合实现条件
1)有外键或者多对多多关系
2)有choice选项
组合实现原理
1)利用上次访问的URL中参数的值,来等记传递的参数
2)全部数据参数为0,其他参数为数据的id
3)第一个默认参数都为0,即是全部数据
三:示例
model.py
from django.db import models # Create your models here. class Category(models.Model): caption = models.CharField(max_length=16) # class ArticleType(models.Model): # caption = models.CharField(max_length=16) class Article(models.Model): title = models.CharField(max_length=32) content = models.CharField(max_length=255) category = models.ForeignKey(Category) # article_type = models.ForeignKey(ArticleType) type_choice = ( (1,'Python'), (2,'OpenStack'), (3,'Linux'), ) article_type_id = models.IntegerField(choices=type_choice)