Hey dev.to community!
In my very 1st post where, I have decided to learn django by building small projects. Here is an update on my progress:
- Did the initial project setup and created a Products app.
- Created a Product model with slug field which is generated automatically.
- With slugs SEO-friendly URLs can be created(will write more about this in future post).
- Created RESTful endpoints(GET, POST, PUT and DELETE).
- Create Product serializer.
I am amazed by how using a few lines of code these APIs can be written utilising Django REST framework generic views. These generic views simplifies the creation of API endpoints for performing CRUD operations. For example, in this project I have created just two views which handles CRUD operations in few lines of code.
- ProductListCreateView: Uses generics.ListCreateAPIView to get list of all the products(via GET request) and create a new product(via POST request).
- ProductDetailView: Uses generics.RetrieveUpdateDestroyAPIView to get a single product(lookup based on slug field), PUT request to update a product, DELETE request to remove a product.
Another good thing is, Browsable API provided in DRF. One can interact with APIs, test and debug it.
Next, I will be working on Categories of the product, expand CRUD operation to categories and get into django admin interface. Also attached some screenshots of the APIs and code.
Complete code available here.
Top comments (0)