More than a question, it is a query, I am currently with an api serving data, and I have reached the following situation, I have a user preferences table, where the configuration options of each user are stored, with json, I do a get and it returns all the data from that table, and then I have to filter that data with the user id that is logged in, my point is, there is another way to do this, that is, with mysql in the query I put the user id and only It returned the data of that user, here it loads the data of all the users and then I have to filter. As I am inexperienced, I fear that if I have a record with more than a thousand data, and in the end I only need 1 of those data, I have to load all that, and in the end it would affect the performance of my page.
It's already too late to go back with the api, I would like to know if there is a solution, or maybe I'm exaggerating and this does not affect performance.
Thanks in advance.
Just as you do it in MySQL so it is done in djangorestframework . It's much easier if you use models in your ViewSets
If you have a ViewSet for your model
Usuario
:You just have to add this to your routes:
And the routes are automatically generated:
^accounts/$
, is called'usuarios-list'
^accounts/{pk}/$
and it is called'usuarios-retail'
And it has the most common verbs,
POST
,GET
,PUT
,UPDATE
,DELETE
andPATCH
, depending on what you have configured.I recommend that you consult the documentation of the project, which is very complete, and that you follow the rules of the How to make a complete, minimal and verifiable example guide when asking your questions.