There must be a problem with super(InviteManager, self).get_query_set()
here but I don't know what to use. When I look through the RelatedManager of a user instance,
len(Invite.objects.by_email()) == len(user.invite_set.by_email())
Even if the user does not have any invites. However, user.invite_set.all() correctly returns all of the Invite objects that are keyed to the User object.
class InviteManager(models.Manager):
''' with this we can get the honed querysets like user.invite_set.rejected '''
use_for_related_fields = True
def by_email(self):
return super(InviteManager, self).get_query_set().exclude( email='' )
class Invite(models.Model):
''' an invitation from a user to an email address ...'''
user = models.ForeignKey('auth.User', related_name='invite_set')
email = models.TextField( blank=True, )
objects = InviteManager()
'''
u.invite_set.by_email() returns everything that Invite.objects.by_email() does
u.invite_set.all() properly filters Invites and returns only those where user=u
'''