I am modelling social relationships, and to do this I have a
relationship model with 2 foreign keys to users, a 'from_user' and a
'to_user' -- in essence, this looks like a Many-to-many table between
users and can probably act like one.
So what I'm trying to do is, mimicking django's
ManyRelatedObjectsDescriptor, create a RelatedManager dynamically that
will access the relationship table.
It's almost working right, except for the last part of the WHERE query
that's being generated:
In [5]: co = User.objects.get(username='coleifer')
In [6]: co.relationships.all()
Out[6]: []
In [8]: connection.queries.pop()
Out[8]:
SELECT "auth_user"."id", etc, etc
FROM "auth_user"
INNER JOIN "relationships_relationship"
ON ("auth_user"."id" = "relationships_relationship"."from_user_id")
WHERE "relationships_relationship"."id" = 69327
LIMIT 21
the where should read "relationships_relationshpi"."to_user_id" =
69327
Anybody know how to fix the WHERE clause? Is there a better way to
achieve this functionality?