> I'm sorry, but the problem with it is that it isn't symmetrical.
> 
> A part of my Profile-model looks like this:
> class Profile(models.Model):
>     user = models.ForeignKey(User)
>     friends = models.ManyToManyField("self")
> 
> This makes it very easy to create and maintain a relationship
> between users - but I have no idea how to specify the friendship
> type. Is it even possible?

Yes, it's possible...The models I provided do precisely that. A
M2M relationship uses/creates/maintains a table that Django keeps
rather well hidden from you unless you go looking for it or
poking in dark SQL corners.  In your case, it's likely a table
called "app_profile_profile" or "app_profile_friends" or
something of the like.  It consists of merely two columns:  two
foreign keys just as my Friendship model did.  What you describe
is wanting to add a column to this table.  This is done by
promoting it to a full model.

If you need the syntactic sugar, you can use the related_name
parameter:

 class Friendship(Model):
         person = Person(related_name="friends")
         friend = Person(related_name="thinks_i_am_a_friend")
         description = ForeignKey(FriendshipType)
         known_since = DateTimeField()

This allows you to iterate through

        p = Person.objects.get(id=1)
        friends = p.friends

rather than iterating through

        friends = p.friendship_set

which you can then use as

        for f in friends:
                print f.friend, ' is my ', f.description

You can also find out who thinks a person is a friend:

        friend_of = p.thinks_i_am_a_friend
        for f in friend_of:
                print "I am %s's %s whether or not they are my friend" % (
                        f.person, f.description)

This also meets your criterion that, X can consider Y a friend,
but Y doesn't have to consider X a friend.  Which does reflect
the real world.  Imagine if "description" was "Mom".  If X is Y's
mom, but Y certainly wouldn't be X's mom.  Unless you live in
some freaky world of inbreeding where you married your own father. :)

-tim






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

Reply via email to