On Wed, Apr 22, 2009 at 11:07 AM, eli <eliasz.wont...@gmail.com> wrote:
> > Thank You Alex. This patch will be available in Django 1.1 ? > > On 22 Kwi, 16:56, Alex Gaynor <alex.gay...@gmail.com> wrote: > > On Wed, Apr 22, 2009 at 10:49 AM, eli <eliasz.wont...@gmail.com> wrote: > > > > > Hi, > > > > > I have a problem with GenericRelation ... > > > > > My code: > > > > > class Comment(models.Model): > > > text = models.TextField() > > > content_type = models.ForeignKey(ContentType, blank=True, > > > null=True) > > > object_id = models.PositiveIntegerField(blank=True, null=True) > > > content_object = generic.GenericForeignKey('content_type', > > > 'object_id') > > > > > class Model1(models.Model): > > > name = models.CharField(max_length=255) > > > comments = generic.GenericRelation(Comment) > > > > > class Model2(models.Model): > > > name = models.CharField(max_length=255) > > > comments = generic.GenericRelation(Comment) > > > > > class Model3(models.Model): > > > name = models.CharField(max_length=255) > > > comments = generic.GenericRelation(Comment) > > > > > In my db ( Comment table): > > > > > id | text | content_type_id | object_id | > > > > --------------------------------------------------------------------------- > > > 1 | lorem.. | 12 | 1 | > > > 2 | lorem.. | 13 | 1 | > > > 3 | lorem.. | 14 | 1 | > > > > > > a = Model1.objects.annotate(comment_cnt=Count('comments')) > > > > print a.comments > > > > 3 > > > > > > b = Model2.objects.annotate(comment_cnt=Count('comments')) > > > > print b.comments > > > > 3 > > > > > > c = Model3.objects.annotate(comment_cnt=Count('comments')) > > > > print c.comments > > > > 3 > > > > > It's bug.. It should by only 1 comment for each models. I tried with > > > distinct=True and related_name, but it does not work correctly.. > > > > > Thanks for help. > > > > > regards. > > > > > This a bug in Django right now, and there's a ticket for it: > > > > http://code.djangoproject.com/ticket/10870 > > > > There's a patch here, but it doesn't completely work. > > > > Alex > > > > -- > > "I disapprove of what you say, but I will defend to the death your right > to > > say it." --Voltaire > > "The people's good is the highest law."--Cicero > > > I doubt it, since a) the patch isnt' fully working now as I noted, b) aggregation with generic relations has never been advertised as working, so it strikes me as more of a feature than a bug, and we're past the feature freeze. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---