Thanks a lot Rajes, now I understand the situation better

On Fri, Jan 23, 2009 at 7:05 PM, Rajesh Dhawan <rajesh.dha...@gmail.com> wrote:
>
>>
>> class Tag(models.Model):
>>      name = models.CharField(max_length=100)
>>      related = models.ManyToManyField('self', symmetrical=False,
>> through='TagCorrelation', blank=True)
>>
>> class TagCorrelation(models.Model):
>>     from_tag = models.ForeignKey(Tag, related_name='related_source')
>>     to_tag = models.ForeignKey(Tag, related_name='related_target')
>>     common_posts = models.IntegerField(blank=True, null=True)
>>
>> You see, it is a slightly denormalized way to store relation between tags.
>>
>> Now, after reading the docs 
>> athttp://docs.djangoproject.com/en/dev/topics/db/models/, following this
>> esample:
>>
>> # Find all the members of the Beatles that joined after 1 Jan 1961>>> 
>> Person.objects.filter(
>>
>> ...     group__name='The Beatles',
>> ...     membership__date_joined__gt=date(1961,1,1))
>> [<Person: Ringo Starr]
>>
>> it seems that it should be possible to query the using attributes of
>> the intermediate model. So I tried with:
>>
>> Tag.objects.filter(tagcorrelation__common_posts_gt=1)
>>
>> but tt does not work, gives this error:
>>
>> FieldError: Cannot resolve keyword 'tagcorrelation' into field.
>> Choices are: id, name, post, related, related_source, related_target,
>> source, tag
>>
>> Am i missing something?
>
> Yes. TagCorrelation has two Foreign Keys back to Tag. So
> tagcorrelation__* is ambiguous and therefore not supported. Try:
>
> Tag.objects.filter(related_source__common_posts_gt=1)
>
> Or
>
> Tag.objects.filter(related_target__common_posts_gt=1)
>
> -Rajesh D
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to