hi,

imagine the following model:

class Person(Model):
        name = Charfield(maxlength=100)
        friends = ManyToManyField('self')


this works fine, but it's not enough for me :-(

i need to add some extra data to that relation.
i need to know WHO created that is-a-friend-of relation, and WHEN he 
created it.

so i went with:

class Person(Model):
        name = CharField(maxlength=100)

class Relation(Model):
        person1 = ForeignKey(Person, related_name = 'friends1')
        person2 = ForeignKey(Person, related_name = 'friends2')
        creator = ForeignKey(User)
        
now this is fine, but now:

when i have a Person object. how do i get all his friends?

(let's say p is a Person)

this works:

friends = [rel.person1 for rel in p.relations1.all()]

isn't there a way to do this in one query?

Character.objects.filter(relations1__person2__name__exact = 'bla')
unfortunately does not work :-(

generally, what is the best approach for these situations?


thanks,
gabor

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

Reply via email to