0

I am using the ParsePy from https://github.com/dgrtwo/ParsePy to access our Parse DB (it works really easy, almost out of the box for me, btw).

The problem I have is that want to get joined data from two classes.
We have a UserVote class that is linked to the User class.
According to the example I see that I can use the select_related to get the attributes of User as well as those of UserVote.

The question is how would I access the attributes of the related object?
Specifically User has an attribute named username and I can't find it also under vote or under vote.user anywhere.

I am running the following code:

allvotes = UserVote.Query.all().select_related("User")
for vote in allvotes:
   if hasattr(vote, 'username') or hasattr(vote, 'user') and hasattr(vote.user, 'username'):
            print vote 

In the debugger I do see that I get votes, and that there is an attribute vote.user but I find no vote that holds a username as I expected.

I get no output for the above code.

Lafexlos
  • 7,618
  • 5
  • 38
  • 53
drorsun
  • 881
  • 1
  • 8
  • 22

1 Answers1

1

Saw that no one answered and meanwhile I got it working as follows, not sure why I was having problems initially, probably some UserVote records had no user pointer.

This is the query I use to retrieve the userVotes -

votes = UserVote.Query.filter(public=True,user__exists=True).order_by("-createdAt").select_related("user")

And then basically I can use use vote.user.username or for any other user attribute

drorsun
  • 881
  • 1
  • 8
  • 22