[Answered ]-Django โ€“ Problem with Model Manager โ€“ Query

1๐Ÿ‘

โœ…

I think your code is not working because get_production calls super().get_queryset(), which returns a new QuerySet, without any filters applied, not based on the Queryset in the reverse look up in companyinvolved_set

Your best bet is to add a @property annotation to access the filtered list through your FeatureFilm model

@property
def production_companies(self):
        return [company for company in self.companyinvolved_set.all() if company.company_role == 'Produktion' and company.is_production_list]

Then add this to your template:

<td>{% for production in project.production_companies %}{{production.company_involved.name}}{% endfor %}</td>

And to prevent a lot of queries, change the get_queryset method in your view to this:

def get_queryset(self):
    queryset = FeatureFilm.objects.prefetch_related('companyinvolved_set').all()
    return queryset
๐Ÿ‘คNico Griffioen

Leave a comment