Skip to content
Advertisement

Showing all the users who have set their country same as request.user

I am building a BlogApp and I am trying to show all the users which set their Countries similar to request.user.

For Example : If user_1 is request.user and selected state choice Victoria and country Australia and then user_2 registered and set the same state Victoria and country Australia.

So i want to show all the users that have set their Country and state same to request.user BUT When i access these types of users then It is just showing all users of same country BUT it is not showing of same state.

models.py

JavaScript

views.py

JavaScript

When i try to access {{ show }} in template then it shows two user have set their country same to request.user BUT When i try to access {{ show_state }} in template it shows nothing.

I have no idea, what am i doing wrong in accessing. Any help would be Appreciated. Thank You in Advance.

Note :- I am using external library to show country and state choices in html.

Advertisement

Answer

There seems to be a filter problem.

JavaScript

What you want to do is filter using request.user.profile.state and request.user.profile.country.

JavaScript

While this should solve your current problem.

Suggestion

With Django, you can actually filter Profiles with country and state that matches user’s in the same query.

JavaScript
Advertisement