Juan Carlos Asuncion February 2016

Django: add a list filter option to filter related models under parent model

I would like to request assistance in this matter

I have the following models:

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)

and 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]

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.

EDIT

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

Answers


Juan Carlos Asuncion February 2016

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]

Post Status

Asked in February 2016
Viewed 1,333 times
Voted 4
Answered 1 times

Search




Leave an answer