PageRenderTime 92ms CodeModel.GetById 50ms app.highlight 3ms RepoModel.GetById 38ms 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
 1from django.db import models
 2from django.contrib.contenttypes.models import ContentType
 3from django.utils.encoding import force_unicode
 4
 5class CommentManager(models.Manager):
 6
 7    def in_moderation(self):
 8        """
 9        QuerySet for all comments currently in the moderation queue.
10        """
11        return self.get_query_set().filter(is_public=False, is_removed=False)
12
13    def for_model(self, model):
14        """
15        QuerySet for all comments for a particular model (either an instance or
16        a class).
17        """
18        ct = ContentType.objects.get_for_model(model)
19        qs = self.get_query_set().filter(content_type=ct)
20        if isinstance(model, models.Model):
21            qs = qs.filter(object_pk=force_unicode(model._get_pk_val()))
22        return qs