PageRenderTime 33ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/django/contrib/comments/managers.py

https://code.google.com/p/mango-py/
Python | 22 lines | 12 code | 3 blank | 7 comment | 1 complexity | e8f744ea6faae4c6e51cd89475b45363 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. from django.db import models
  2. from django.contrib.contenttypes.models import ContentType
  3. from django.utils.encoding import force_unicode
  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=force_unicode(model._get_pk_val()))
  19. return qs