如何在ListView上创建工作搜索栏

2024-09-30 16:34:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我在youtube和google上搜索,在ListView上创建一个可用的搜索栏,但没有人在class allPostList(ListView):上使用

你能解释一下怎么做吗

这是我的密码

table.html

{% block container_content %}
                <form class="d-none d-sm-inline-block mr-auto ml-md-3 my-2 my-md-0 mw-100 navbar-search justify-content-end">
                    <div class="input-group"><input class="bg-light form-control border-0 small" type="text" name="q" placeholder="Search for ...">
                        <div class="input-group-append"><button class="btn btn-primary py-0" type="button"><i class="fas fa-search"></i></button></div>
                     </div>
                </form>
{% endblock %}

在table.html上,我没有显示所有的代码,因为它太多太乱了,但这是表单html代码,它是在html上创建的,而不是在forms.py中创建的

我的观点

class AdminShowAllPostList(ListView):
    model = Post
    template_name = 'admini/table.html'
    ordering = ['category']
    paginate_by = 10

a screenshoot on table.html

models.py(如果需要)

class Post(models.Model):
    title = models.CharField(max_length=255)
    title_tag = models.CharField(max_length=255)
    page_link = models.SlugField(max_length=255, unique=True)
    body = RichTextField(blank=True, null=True,
                         config_name='special',
                         external_plugin_resources=[
                             ('youtube',
                              '/static/ckeditor_plugins/youtube/youtube/',
                              'plugin.js'),
                         ]
                         )
    category = models.ForeignKey(Category, default="", on_delete=models.CASCADE)
    # parent_check = models.CharField(max_length=255)
    meta_description = models.TextField(null=False, blank=False)
    meta_keyword = models.TextField(blank=False, null=False)

我真的希望搜索栏可以使用复杂的Q查找 谢谢


Tags: namepydivformfalseinputyoutubemodels