managers.py 754 B

12345678910111213141516171819202122
  1. from django.db import models
  2. from django.dispatch import dispatcher
  3. from django.contrib.contenttypes.models import ContentType
  4. class CommentManager(models.Manager):
  5. def in_moderation(self):
  6. """
  7. QuerySet for all comments currently in the moderation queue.
  8. """
  9. return self.get_query_set().filter(is_public=False, is_removed=False)
  10. def for_model(self, model):
  11. """
  12. QuerySet for all comments for a particular model (either an instance or
  13. a class).
  14. """
  15. ct = ContentType.objects.get_for_model(model)
  16. qs = self.get_query_set().filter(content_type=ct)
  17. if isinstance(model, models.Model):
  18. qs = qs.filter(object_pk=model._get_pk_val())
  19. return qs