1

How to add filter(is_public=True) to Question?

Category.objects.add_related_count(
  Category.objects.filter(is_public=True), 
  Question,
  'category',
  'question_counts',
  cumulative=True)
Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555
Stanislav
  • 59
  • 2
  • 7

1 Answers1

1

You can use the extra_filters=… parameter of the .add_related_count(…) method [Django-doc]:

Category.objects.add_related_count(
    Category.objects.filter(is_public=True), 
    Question,
    'category',
    'question_counts',
    cumulative=True,
    extra_filters={'is_public': True}
)
Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555