In Django REST Framework, views are responsible for processing HTTP requests and returning appropriate responses. Djuix simplifies this process by leveraging the power of ModelViewSet
while providing intuitive ways to customize and extend functionality.
By default, Djuix creates views using ModelViewSet
, a powerful feature of Django REST Framework. This approach automatically provides a full set of CRUD (Create, Read, Update, Delete) operations with minimal code setup.
Here's what you get out of the box with each ModelViewSet
:
Instead of writing separate view functions for each of these operations, Djuix sets them up automatically when you create a view for your model.
While CRUD operations cover many use cases, you often need more specialized functionality. This is where Djuix's custom functions come into play. These allow you to easily extend your views without diving into complex Django code.
Djuix supports a variety of custom function types:
Djuix provides several helpers and value sources to make your custom functions more flexible and powerful.
When creating custom functions, you can draw data from various sources:
Djuix provides several helpers and value sources to make your custom functions more flexible and powerful.
When creating custom functions, you can draw data from various sources:
Djuix supports a range of filter operations, allowing for precise data retrieval and manipulation. Some key filter operations include:
These filter operations can be applied to various field types in to refine searches and data retrieval.
These operations can be applied to various field types, allowing for refined searches and data retrieval. For a complete list of filter operations, refer to the Django documentation.
One of the most powerful features of Djuix's custom functions is the ability to chain operations. This allows you to create complex logic flows within a single custom function.
Here's how chaining works:
Let's walk through a practical example of chained operations in a custom function. We'll create a custom PUT method to update a patient's record, demonstrating how Djuix allows you to build complex logic with ease.
Override the default PUT method to update a patient's record based on the request body, but only if the patient ID exists.
CHECK: Verify patient id
First, we need to check if the patient ID exists in our database.
In this step:
This operation will return a boolean value: True if the patient exists, False otherwise.
IF_CONDITION: Handle Patient Existence
RETURN:
After setting up your custom function, you can view the generated code to understand how Djuix translates your GUI actions into Django code.
This shows how Djuix translates your GUI-based custom function into a Django view method.
We can get to do more scallable custom operations like this involving GET CHECK AGGREGATE etc. Check out our tutorial for more usage