Query set with multiple level

Hello Django guys,

I have this in my models :

class Affaires(models.Model):
   def get_search_count(self):
        return self.search_set.query_set.count()

class Search(models.Model):
   affaire = models.ForeignKey(Affaires, on_delete=models.SET_NULL, null=True)
   def get_query_count(self):
        return self.query_set.count()

class Query(models.Model):
   search = models.ForeignKey(Search, on_delete=models.SET_NULL, null=True)

{{ my_affaire.get_search_count }}

But I have this error "‘RelatedManager’ object has no attribute ‘search_query_set’’

Do you know what i am doing wrong to get the the object count for a second level ?

Thanks you


Hi thais781,

What is Search’s self.query_set?

Also I think the code you’ve shared is different than the code that was used to generate the error, or you may need to include additional code. The error is indicating there’s a problem with accessing search_query_set, but I don’t see that in the code you’ve shared.