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.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---