Azd325
Azd325

Reputation: 6140

Filter on content_object django comments

I have this simple model of a Video

class Video(models.Model)
    name = models.CharField()
    active = models.BooleanField()

Currently I filter for all comments on a video like this.

comments = Comment.objects.for_model(Video)

This there an easy way to exclude where Video "active" is false on this queryset.

Thanks

Upvotes: 1

Views: 819

Answers (1)

jproffitt
jproffitt

Reputation: 6355

You could filter on the object_pk of the comment. Just make sure it is in the list of active video ids. For example:

active_videos_ids = Video.objects.filter(active=True).values_list('id', flat=True)
comments = Comment.objects.for_model(Video).filter(object_pk__in=active_videos_ids)

I've never actually used the comments app before, so let me know if you have any problems with this, and I will dig into it.

Upvotes: 2

Related Questions