On May 14, 2008, at 5:53 PM, Russell Keith-Magee wrote:
> Hi James,
>
> It sounds like you might be looking for ticket #6095 [1]. This lets
> you define an intermediate model to use for m2m relations. This allows
> you to put attributes on the arc, query over the arc attributes, and
> be symmetrical (or not).
As long as the arc model can be defined without modifying the node
model.
For example, in one use case, I'd like the nodes to be able to be
django.contrib.auth Users.
To make it more concrete, here is what I am currently doing in one app
to retrieve friendship relationships between django.contrib.auth Users:
class FriendshipManager(models.Manager):
def friends_for_user(self, user):
friends = []
for friendship in self.filter(user_1=user):
friends.append({"friend": friendship.user_2,
"friendship": friendship})
for friendship in self.filter(user_2=user):
friends.append({"friend": friendship.user_1,
"friendship": friendship})
return friends
class Friendship(models.Model):
user_1 = models.ForeignKey(User, related_name="friends_1")
user_2 = models.ForeignKey(User, related_name="friends_2")
objects = FriendshipManager()
There could, of course, be extra fields on Friendship, but in the
above case there aren't and so it's just a normal symmetrical M2M
relationships except the User model is used unmodified.
James
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---