Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3630

Is there a way to have a user enter a url query and have a single function filter a database?

$
0
0

I'm playing with the Django rest framework and PostgreSQL, building an API that returns data on all of the stats from this NBA season. Rather than having a function to return stats for each category, such as:

 @api_view(['GET'])def sortByRebounds(request):"""Returns all stats in the database sorted by rebounds per game"""    string = Nba_stats.objects.values_list('name', 'team', 'rpg').order_by('rpg').reverse()    return Response(string)

It possible to have a single function capable of filtering and returning data based on what the user types in the url?

For example a function called sortBy that takes in a category as a parameter and a url "api/sortby/<str:category>/" where a user can type "api/sortby/rebounds" and receive the data on rebounds or "api/sortby/assists" and receive everything on assists.


Viewing all articles
Browse latest Browse all 3630

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>