How does django convert query into sql? - django-rest-framework

I have a model User
Suppose I write in my views.py
users = User.objects.all()
When does django convert it to sql query? During the request or during the server loading? Which file in django does the conversion?

Related

Date And Multiple Field Filter Through SPATIE query builder for post request In Laravel 8

I go through 'SPATIE query builder' documentation and find they cannot describe properly how to post methods implemented. I need to filter data based on multiple parameters including the data add date filter, and I am using the POST method, How I can achieve this for 'SPATIE query builder'.
I can Filter 1 field by writing below code
$data = QueryBuilder::for(EmpData::where('empAddedByAgent', $request->searchAgent))
->get();
The form Look Like Below Image

I want to create routes from database Data in Laravel

I want to retrieve data from the database and create the dynamic route.
For example, in Laravel web route file we write :
Route::get('/{slug}', function($slug){
return $slug;
});
So, I want to create this code after retrieving data from the database. and based on the data I can create the dynamic route with params or passing model data to the view.
And also how do I create dynamic view files. Like for different layout or from the database data.
Thanks in Advance.

convert DB array output to Eloquent Model for using API Resources

i want to use DB::select and DB::table in my laravel project
how can i get Eloquent Models from them ?
they returns array and can't used with API Resources

how to show html tables in django rest framework instead raw data using function based views?

i want to get html tables instead of raw data by function based views ,
in class based views html tables and raw data appear but in function based views raw data appears only but html tables not.
so what i can do to show html tables with FBV ?
Have you looked at this https://www.django-rest-framework.org/topics/html-and-forms/#rendering-html? Example is for class-based-view, but you can use it with functions
Make a decorator for renderer_classes and check what type of response should you return, if request.accepted_renderer.format == 'html':
P.S. I could hardly imagine, that you are not able to do this in FBV, when you already have same in classes

Is it good to use raw query instead of Eloquent in Laravel

I have a complex business logic to retrieve data from a MYSQL database.
I am using laravel eloquent query builder to retrieve data but if I call a MYSQL procedure using raw query in laravel, I would not be able to exploit features of laravel like model relationships or pagination, etc.
What is the correct way to handle this situation? Should I write my logic in proc (use joins (model relationships) ) and use it as raw query or is there any better approach?

Resources