Filter with first item from a ManyToMany Django

3

I have this in my template:

{% for j in jobs %}
    <tbody>
        {% if j.background.all.0.active == False %}
        ...

I need to make a filter in the view similar to this.

I tried

jobs = jobs.filter(background__first__active=False)

But I know it's completely wrong.

To know background is a ManyToMany that contains a field called active, but I just want to get the first item.

How do I make this filter?

    
asked by anonymous 20.08.2016 / 18:46

2 answers

1

See: link

You can try something like:

jobs = jobs.filter(background__active=False).first()
    
02.09.2016 / 20:06
1

Corroborating the Regis response, you can do as follows:

jobs = Jobs.objects.filter(background_active=False)[0]
    
04.12.2018 / 00:31