Trying and expand the contrib.auth.user model and add a "relatipnships" manage

Posted by dotty on Stack Overflow See other posts from Stack Overflow or by dotty
Published on 2011-01-06T22:48:29Z Indexed on 2011/01/06 22:53 UTC
Read the original article Hit count: 240

Filed under:
|
|
|
|

I have the following model setup.

from django.db import models
from django.contrib.auth.models import User

class SomeManager(models.Manager):
    def friends(self):
        # return friends bla bla bla


class Relationship(models.Model):
    """(Relationship description)"""
    from_user = models.ForeignKey(User, related_name='from_user')
    to_user = models.ForeignKey(User, related_name='to_user')
    has_requested_friendship = models.BooleanField(default=True)
    is_friend = models.BooleanField(default=False)

    objects = SomeManager()

relationships = models.ManyToManyField(User, through=Relationship, symmetrical=False)
relationships.contribute_to_class(User, 'relationships')

Here i take the User object and use contribute_to_class to add 'relationships' to the User object. The relationship show up, but if call User.relationships.friends it should run the friends() method, but its failing. Any ideas how i would do this?

Thanks

© Stack Overflow or respective owner

Related posts about python

Related posts about django