一:组合搜索

  组合搜索可以用来实现快速查询。效果图举例。瓜子网站选车

  38)django-组合搜索

    注意: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)
View Code

相关文章:

  • 2021-12-04
  • 2022-12-23
  • 2021-05-19
  • 2022-12-23
  • 2022-12-23
  • 2021-12-15
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-28
  • 2021-07-10
  • 2021-09-21
  • 2021-10-08
  • 2021-08-19
相关资源
相似解决方案