We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Refactor idea to use a4 comments and ratings queryset
https://github.com/liqd/adhocracy4/pull/20

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `euth/ideas/models.py`
Content:
```
1 from autoslug import AutoSlugField
2 from ckeditor.fields import RichTextField
3 from django.contrib.contenttypes.fields import GenericRelation
4 from django.db import models
5 
6 from adhocracy4 import transforms
7 from adhocracy4.comments import models as comment_models
8 from adhocracy4.images import fields
9 from adhocracy4.modules import models as module_models
10 from adhocracy4.ratings import models as rating_models
11 
12 
13 class IdeaQuerySet(models.QuerySet):
14 
15     def _rate_value_condition(self, value):
16         return models.Case(
17             models.When(ratings__value=value, then=models.F('ratings__id')),
18             output_field=models.IntegerField()
19         )
20 
21     def annotate_positive_rating_count(self):
22         return self.annotate(
23             positive_rating_count=models.Count(
24                 self._rate_value_condition(1),
25                 distinct=True  # needed to combine with other count annotations
26             )
27         )
28 
29     def annotate_negative_rating_count(self):
30         return self.annotate(
31             negative_rating_count=models.Count(
32                 self._rate_value_condition(-1),
33                 distinct=True  # needed to combine with other count annotations
34             )
35         )
36 
37     def annotate_comment_count(self):
38         return self.annotate(
39             comment_count=models.Count(
40                 'comments',
41                 distinct=True  # needed to combine with other count annotations
42             )
43         )
44 
45 
46 class Idea(module_models.Item):
47     slug = AutoSlugField(populate_from='name', unique=True)
48     name = models.CharField(max_length=120)
49     description = RichTextField()
50     image = fields.ConfiguredImageField(
51         'idea_image',
52         upload_to='ideas/images',
53         blank=True,
54     )
55     ratings = GenericRelation(rating_models.Rating,
56                               related_query_name='idea',
57                               object_id_field='object_pk')
58     comments = GenericRelation(comment_models.Comment,
59                                related_query_name='idea',
60                                object_id_field='object_pk')
61 
62     objects = IdeaQuerySet.as_manager()
63 
64     def __str__(self):
65         return self.name
66 
67     def save(self, *args, **kwargs):
68         self.description = transforms.clean_html_field(
69             self.description)
70         super(Idea, self).save(*args, **kwargs)
71 
72     def get_absolute_url(self):
73         from django.core.urlresolvers import reverse
74         return reverse('idea-detail', args=[str(self.slug)])
75
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/euth/ideas/models.py b/euth/ideas/models.py
--- a/euth/ideas/models.py
+++ b/euth/ideas/models.py
@@ -6,41 +6,13 @@
 from adhocracy4 import transforms
 from adhocracy4.comments import models as comment_models
 from adhocracy4.images import fields
+from adhocracy4.models import query
 from adhocracy4.modules import models as module_models
 from adhocracy4.ratings import models as rating_models
 
 
-class IdeaQuerySet(models.QuerySet):
-
-    def _rate_value_condition(self, value):
-        return models.Case(
-            models.When(ratings__value=value, then=models.F('ratings__id')),
-            output_field=models.IntegerField()
-        )
-
-    def annotate_positive_rating_count(self):
-        return self.annotate(
-            positive_rating_count=models.Count(
-                self._rate_value_condition(1),
-                distinct=True  # needed to combine with other count annotations
-            )
-        )
-
-    def annotate_negative_rating_count(self):
-        return self.annotate(
-            negative_rating_count=models.Count(
-                self._rate_value_condition(-1),
-                distinct=True  # needed to combine with other count annotations
-            )
-        )
-
-    def annotate_comment_count(self):
-        return self.annotate(
-            comment_count=models.Count(
-                'comments',
-                distinct=True  # needed to combine with other count annotations
-            )
-        )
+class IdeaQuerySet(query.RateableQuerySet, query.CommentableQuerySet):
+    pass
 
 
 class Idea(module_models.Item):

{"golden_diff": "diff --git a/euth/ideas/models.py b/euth/ideas/models.py\n--- a/euth/ideas/models.py\n+++ b/euth/ideas/models.py\n@@ -6,41 +6,13 @@\n from adhocracy4 import transforms\n from adhocracy4.comments import models as comment_models\n from adhocracy4.images import fields\n+from adhocracy4.models import query\n from adhocracy4.modules import models as module_models\n from adhocracy4.ratings import models as rating_models\n \n \n-class IdeaQuerySet(models.QuerySet):\n-\n-    def _rate_value_condition(self, value):\n-        return models.Case(\n-            models.When(ratings__value=value, then=models.F('ratings__id')),\n-            output_field=models.IntegerField()\n-        )\n-\n-    def annotate_positive_rating_count(self):\n-        return self.annotate(\n-            positive_rating_count=models.Count(\n-                self._rate_value_condition(1),\n-                distinct=True  # needed to combine with other count annotations\n-            )\n-        )\n-\n-    def annotate_negative_rating_count(self):\n-        return self.annotate(\n-            negative_rating_count=models.Count(\n-                self._rate_value_condition(-1),\n-                distinct=True  # needed to combine with other count annotations\n-            )\n-        )\n-\n-    def annotate_comment_count(self):\n-        return self.annotate(\n-            comment_count=models.Count(\n-                'comments',\n-                distinct=True  # needed to combine with other count annotations\n-            )\n-        )\n+class IdeaQuerySet(query.RateableQuerySet, query.CommentableQuerySet):\n+    pass\n \n \n class Idea(module_models.Item):\n", "issue": "Refactor idea to use a4 comments and ratings queryset\nhttps://github.com/liqd/adhocracy4/pull/20\n", "before_files": [{"content": "from autoslug import AutoSlugField\nfrom ckeditor.fields import RichTextField\nfrom django.contrib.contenttypes.fields import GenericRelation\nfrom django.db import models\n\nfrom adhocracy4 import transforms\nfrom adhocracy4.comments import models as comment_models\nfrom adhocracy4.images import fields\nfrom adhocracy4.modules import models as module_models\nfrom adhocracy4.ratings import models as rating_models\n\n\nclass IdeaQuerySet(models.QuerySet):\n\n    def _rate_value_condition(self, value):\n        return models.Case(\n            models.When(ratings__value=value, then=models.F('ratings__id')),\n            output_field=models.IntegerField()\n        )\n\n    def annotate_positive_rating_count(self):\n        return self.annotate(\n            positive_rating_count=models.Count(\n                self._rate_value_condition(1),\n                distinct=True  # needed to combine with other count annotations\n            )\n        )\n\n    def annotate_negative_rating_count(self):\n        return self.annotate(\n            negative_rating_count=models.Count(\n                self._rate_value_condition(-1),\n                distinct=True  # needed to combine with other count annotations\n            )\n        )\n\n    def annotate_comment_count(self):\n        return self.annotate(\n            comment_count=models.Count(\n                'comments',\n                distinct=True  # needed to combine with other count annotations\n            )\n        )\n\n\nclass Idea(module_models.Item):\n    slug = AutoSlugField(populate_from='name', unique=True)\n    name = models.CharField(max_length=120)\n    description = RichTextField()\n    image = fields.ConfiguredImageField(\n        'idea_image',\n        upload_to='ideas/images',\n        blank=True,\n    )\n    ratings = GenericRelation(rating_models.Rating,\n                              related_query_name='idea',\n                              object_id_field='object_pk')\n    comments = GenericRelation(comment_models.Comment,\n                               related_query_name='idea',\n                               object_id_field='object_pk')\n\n    objects = IdeaQuerySet.as_manager()\n\n    def __str__(self):\n        return self.name\n\n    def save(self, *args, **kwargs):\n        self.description = transforms.clean_html_field(\n            self.description)\n        super(Idea, self).save(*args, **kwargs)\n\n    def get_absolute_url(self):\n        from django.core.urlresolvers import reverse\n        return reverse('idea-detail', args=[str(self.slug)])\n", "path": "euth/ideas/models.py"}], "after_files": [{"content": "from autoslug import AutoSlugField\nfrom ckeditor.fields import RichTextField\nfrom django.contrib.contenttypes.fields import GenericRelation\nfrom django.db import models\n\nfrom adhocracy4 import transforms\nfrom adhocracy4.comments import models as comment_models\nfrom adhocracy4.images import fields\nfrom adhocracy4.models import query\nfrom adhocracy4.modules import models as module_models\nfrom adhocracy4.ratings import models as rating_models\n\n\nclass IdeaQuerySet(query.RateableQuerySet, query.CommentableQuerySet):\n    pass\n\n\nclass Idea(module_models.Item):\n    slug = AutoSlugField(populate_from='name', unique=True)\n    name = models.CharField(max_length=120)\n    description = RichTextField()\n    image = fields.ConfiguredImageField(\n        'idea_image',\n        upload_to='ideas/images',\n        blank=True,\n    )\n    ratings = GenericRelation(rating_models.Rating,\n                              related_query_name='idea',\n                              object_id_field='object_pk')\n    comments = GenericRelation(comment_models.Comment,\n                               related_query_name='idea',\n                               object_id_field='object_pk')\n\n    objects = IdeaQuerySet.as_manager()\n\n    def __str__(self):\n        return self.name\n\n    def save(self, *args, **kwargs):\n        self.description = transforms.clean_html_field(\n            self.description)\n        super(Idea, self).save(*args, **kwargs)\n\n    def get_absolute_url(self):\n        from django.core.urlresolvers import reverse\n        return reverse('idea-detail', args=[str(self.slug)])\n", "path": "euth/ideas/models.py"}]}