|
Revision 8800, 0.8 kB
(checked in by jacob, 3 months ago)
|
Make sure to use force_unicode when looking up comment objects by object_pk. Fixes #8762, and one other bug that nobody's reported yet.
|
| Line | |
|---|
| 1 |
from django.db import models |
|---|
| 2 |
from django.dispatch import dispatcher |
|---|
| 3 |
from django.contrib.contenttypes.models import ContentType |
|---|
| 4 |
from django.utils.encoding import force_unicode |
|---|
| 5 |
|
|---|
| 6 |
class CommentManager(models.Manager): |
|---|
| 7 |
|
|---|
| 8 |
def in_moderation(self): |
|---|
| 9 |
""" |
|---|
| 10 |
QuerySet for all comments currently in the moderation queue. |
|---|
| 11 |
""" |
|---|
| 12 |
return self.get_query_set().filter(is_public=False, is_removed=False) |
|---|
| 13 |
|
|---|
| 14 |
def for_model(self, model): |
|---|
| 15 |
""" |
|---|
| 16 |
QuerySet for all comments for a particular model (either an instance or |
|---|
| 17 |
a class). |
|---|
| 18 |
""" |
|---|
| 19 |
ct = ContentType.objects.get_for_model(model) |
|---|
| 20 |
qs = self.get_query_set().filter(content_type=ct) |
|---|
| 21 |
if isinstance(model, models.Model): |
|---|
| 22 |
qs = qs.filter(object_pk=force_unicode(model._get_pk_val())) |
|---|
| 23 |
return qs |
|---|