django - Is it faster to obtain current user data by using a filter or related object reference? -


which of 2 methods quicker in obtaining current user specific data? example:

class friendprofiledetail(listview):     model = friend     def get_queryset(self):         return self.model.objects.filter(friend_of=self.request.user.profile) 

vs

class friendprofiledetail(listview):     model = friend     def get_queryset(self):          queryset = self.request.user.profile.friends.all()     return queryset 

there absolutely no difference between 2 filters , queries. but, in opinion, the zen of python says: "explicit better implicit.".

so listview corresponding friend model, more straightforward use self.model instead of self.request.user object filtering.

the other thing self.request.user filtering shorter , not use filter() all(), seems simple.

no matter what, result same. choose 1 way , it.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -