Django - How to properly access reverse relationship ManyToManyField -
this models.py (i'm using default django user model well):
class userextended(models.model): user = models.onetoonefield(user, related_name="userextended_set") location = models.foreignkey(location) follow = models.manytomanyfield(user, related_name="follow_set")
now, access list of 'follow' users of particular user (users particular user following), i'd this:
a = user.objects.get(username='a') a.userextended_set.follow.count()
my question is, how list of users whom particular user on 'follow' list of (i.e. following him)? tried this:
# assuming user 'a' on 'follow' list of 1 users (i.e. # assuming .get() return 1 user object). user.objects.get(username='a').follow_set.get().username
but error saying
attributeerror: 'userextended' object has no attribute 'username'
i think need:
user # user userextended.objects.filter(follow=user)
Comments
Post a Comment