本文介绍了Django:添加一个列表过滤器选项来筛选父模型下的相关模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在这个问题上要求协助

I would like to request assistance in this matter

我有以下型号:

class Job(models.Model):
    Job_Position = models.CharField(max_length=30, null=True, unique=True)

class Job_Posting(models.Model):
    fkey = models.ForeignKey("Job", verbose_name="Job Positions", unique=True)

和Admin:

class jobs(admin.TabularInline): 
    model = Job_Posting
    readonly_fields = [ 'fkey',]
    extra = 0

class applicant(admin.ModelAdmin):

    model = Job
    list_display = ('Job_Position')
    list_filter = ['Job_Position']
    inlines = [jobs]

是否可以从内联添加列表过滤器选项?像这样的东西 list_filter = ['Job_Position','Job_Posting.fkey'] 或者例如,当前 list_filter I已显示 Job_Position 下的所有项目(选择一个 Job_Position 显示所有具有该位置的记录),并且我想添加另一个选项过滤所有具有 Job_Posting.fkey 的所有 Job_Position ,同时让我选择查看所有记录

Is it possible to add a list filter option from inline? Something like this list_filter = ['Job_Position', 'Job_Posting.fkey'] or for example, the current list_filter I have shows all items under Job_Position(selecting a Job_Position shows all record that have that position) and I want to add another option filtering all Job_Position that have that specific Job_Posting.fkey while giving me an option to see all the records

你可以这样做还是不可能?或者如果有其他选择会是什么?感谢提前。

Can you do this or it's not just possible? or if there are other options what would it be? Thanks in advance.

编辑

我需要像,过滤所有 Job 在list_filter中有 Job_Posting fkey

I need something like this, filtering all Job that has that Job_Posting, fkey in list_filter

推荐答案

我发现我正在寻找,通过过滤 Job Job_Posting fkey ,我只需要在 list_filter 中添加 Job_Posting__fkey ,如下所示:

I have found what I am looking for Here, to filter Job through Job_Posting fkey, I just need to add Job_Posting__fkey in my list_filter looking like this:

class applicant(admin.ModelAdmin):

    model = Job
    list_display = ('Job_Position')
    list_filter = ['Job_Position', 'Job_Posting__fkey']
    inlines = [jobs]

这篇关于Django:添加一个列表过滤器选项来筛选父模型下的相关模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 02:17